Changing C++ cin

June 15, 2009 at 15:30:50
Specs: Windows XP
When you enter a space ' ' while typing into cin, it will take the first string before the space as the first value and the later one as the next.

so lets say we have this code

cout << "Enter your Name";
cin >> name;
cout << "Enter your age";
cin >> age;

now, lets say a user enters "John Bill"

it would take his name to be John and his age to be Bill.

Is there a way to
a) have the line automatically change it from a ' ' to a '_'?
b) Have it so that it will read that line as that line and have the space ' ' read as a normal character?

See More: Changing C++ cin

Report •

June 16, 2009 at 15:32:14
If name is a std::string, then try using std::getline(std::istream&,
std::string&). If name is a char array, try cin.getline(name, sizeof

Report •
Related Solutions

Ask Question