Basic User Input using cin >>

string 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]

If we want to get full line input, ex. to get a full name from the user, we can use getline.

Full Line Input using getline()

There's two ways to use getline in c++, one being for standard c++ string objects, and the other for classic c strings.

istream::getline()

This method works with the classic C char pointers. The syntax is:

char cstr[256];
cin.getline(cstr,sizeof(cstr));

Global getline()

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: