Input output string

To read string input from the user getline method can be used with the string datatype. You can also use cin for reading string input, but cin will only read string without space, once it encounters space it stops reading further characters.

Program

#include <iostream>
#include <string>

using namespace std;

int main() {

    string name;

    cout << "Enter your name : ";
    getline(cin, name);

    cout << endl << "Hello " << name;

    return 0;
}

Output

Enter your name : Karan
Hello Karan