The string Class Input
Another useful thing to know about a class is what input options are available. For C-style strings, recall, you have three options:
char info[100];cin >> info; // read a wordcin.getline(info, 100); // read a line, discard \ncin.get(info, 100); // read a line, leave \n in queue
For string objects, recall, you have two options:
string stuff;cin >> stuff; // read a wordgetline(cin, stuff); // read a line, discard \n
Both versions of getline() allow for an optional argument that specifies which character to use to delimit input:
cin.getline(info,100,':'); // read up to :, discard :getline(stuff, ':'); // read up to :, discard :
The main operational difference is that the string ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access