Which C++ function is commonly used to read an entire line of text, including spaces?
Options
- A. cin.getline()
- B. cin.readword()
- C. cin.character()
- D. More than one of the above
- E. None of the above
Quiz Practice:
A. cin.getline()
Answer: (A) cin.getline()
cin.getline() can be used to read a complete line of characters, including spaces.
Example:
char name[50];
cin.getline(name, 50);
If the user enters Rahul Kumar, the complete line can be stored in the character array.
This differs from the usual cin >> extraction because formatted extraction normally stops at whitespace.