Strings

P

Pat

I have ran into this problem numerous times during one of my C++ course.
This issue is taking in a string with spaces, for example;
#include <iostream>
#include <string>

using namespace std;

int main()
{
string userInput;

cout << "Please enter your full name: ";
cin >> userInput;

cout << "Your name is: " << userInput << endl;

return 0;
}

This is the problem the user enters the first name, space bar, and then
the last name. Hitting enter the program goes into a loop from hell and
never finishing the program.
Can anyone reference a resource or solution so that I can end this
madness of abnormal termination.

Pat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,184
Messages
2,570,979
Members
47,578
Latest member
LC_06

Latest Threads

Top