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.
- Add new comment
- Read more
- 655 reads


Recent comments
38 weeks 3 days ago
39 weeks 4 days ago
40 weeks 3 days ago
40 weeks 4 days ago
49 weeks 6 days ago
1 year 13 weeks ago
1 year 13 weeks ago
1 year 14 weeks ago
1 year 14 weeks ago
1 year 14 weeks ago