cin >>cin >> a >> bstring inp;
cout << "What is your name? \\n";
cin >> inp;
cout << "Hello " << inp << "! \\n";
The output looks like this:
What is your name?
>> Vari
Hello Vari!
[Finished in 2.29s]
/0 when an empty enter key is pressed.
If we want to get full line input, ex. to get a full name from the user, we can use getline.
getline()There's two ways to use getline in c++, one being for standard c++ string objects, and the other for classic c strings.
This method works with the classic C char pointers. The syntax is:
char cstr[256];
cin.getline(cstr,sizeof(cstr));
This global method works with C++ string objects, and can be called using:
string str;
getline(cin,str);
This is the modern C++ way to use getline. We'll focus on this method.
Example usage: