What happens when the extraction operator cin >> is used to read a string containing spaces?

Options

  • A. It normally stops reading at whitespace
  • B. It always reads the complete line
  • C. It reads only the last word
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. It normally stops reading at whitespace

Detailed Explanation

Answer: (A) It normally stops reading at whitespace

When cin >> is used for string input, formatted extraction normally stops when it encounters whitespace such as a space, tab, or newline.

For example:

string name;
cin >> name;

If the user enters Rahul Kumar, only Rahul is normally extracted into name.

To read the complete line including spaces, getline() is generally more appropriate.