getline()
cin.getline (arrayname, size);
So you want to read an entire line from the keyboard and not be bothered with cin >> getdata; only reading the first word. Then this form of the cin object is for you.
This form accepts an entire line entered from the keyboard terminated by the 'ENTER' key. The newline character created by the 'ENTER' key is replaced by a null '\0' character (which is the terminating character required for character arrays). As you can guess from the code snippet, the line of text is ultimately assigned to arrayname variable, a character array, and only receives the number of characters specified by the second parameter, size.
If the number of characters entered is greater than the number specified by the second parameter size the left-over characters remain in the input queue/stream. Remember, the next cin operation will retrieve either some or all of these characters depending upon the type of cin operation that's applied. If the number of characters is less than the parameter size then the input queue is effectively flushed and will not be a problem for the next cin operation.


Recent comments
3 hours 49 min ago
1 day 3 hours ago
1 day 9 hours ago
1 day 19 hours ago
1 day 20 hours ago
3 weeks 6 days ago
3 weeks 6 days ago
4 weeks 4 hours ago
10 weeks 1 day ago
11 weeks 5 days ago