To make it easier to handle string, the standard C++ library provides a string class.
To include the string class, we need to have this line #include <string> at the header of the file.
#include <iostream> #include <string> using namespace std; void main() { string str; cout << "Please enter your name\n"; cin >> str; cout << "Hello, " << str << "!\n"; }
The operator << is an output operator. cout is the standard output stream. It is used to output a string of characters.
The operator >> (“get from”) is used as an input operator; cin is the standard input stream.