Need help with input

J

JustSomeGuy

Hi. The code below works just fine as long as I enter data.
However it will not produce Null or "" strings if the user hits
enter without entering any data.

std::string pid;
std::string pname;
std::cout << "Enter Patient ID: "; std::cin >> pid;
std::cout << "Enter Patient Name: "; std::cin >> pname;

Why can't I enter a blank string?
 
R

Rolf Magnus

JustSomeGuy said:
Hi. The code below works just fine as long as I enter data.
However it will not produce Null or "" strings if the user hits
enter without entering any data.

It won't? What are the contents of the string when you try?
std::string pid;
std::string pname;
std::cout << "Enter Patient ID: "; std::cin >> pid;
std::cout << "Enter Patient Name: "; std::cin >> pname;

Why can't I enter a blank string?

No idea.
 
J

JustSomeGuy

"What are the contents of the string when you try?"
I don't get a string back until I enter at least one non-white
character.
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top