LearnFrenzy
Sign in Take a free test

Input/Output with cin and cout · Input/Output MCQ · Question 5

How to read a full name with spaces in C++ Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

Which call reads a whole line such as Rahul Kumar Sharma into a std::string?

  • A std::cin >> name;
  • B std::getline(std::cin, name); Correct
  • C std::cin.get(name);
  • D std::cin.read(name);
Correct Answer: Option B

std::cin >> name stops at the first space and would read only "Rahul".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links