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

Correct Answer (Detailed Explanation is Below)

A. cin.getline()

Detailed Explanation

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.