Answers for "getline cpp string"

C++
20

get line C++

// extract to string
#include <iostream>
#include <string>

int main ()
{
  std::string name;

  std::cout << "Please, enter your full name: ";
  std::getline (std::cin,name);
  std::cout << "Hello, " << name << "!\n";

  return 0;
}
Posted by: Guest on November-16-2019
0

getline in c++

#include<bits/stdc++.h>
using namespace std;
#define e  "\n"

int main()
{
    string food, name;
    int age;

    getline(cin,name);// for space
    cin>>age;
    cin.ignore();// to ignore the newline character
    getline(cin,food);
    cout<<name<<" "<<age<<" "<<food<<e;

    return 0;
}
Posted by: Guest on February-07-2022

Browse Popular Code Answers by Language