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 ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.