470,833 Members | 1,564 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Need help with input

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?

Mar 21 '06 #1
4 1662
JustSomeGuy wrote:
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.

Mar 21 '06 #2
Anyone know of an ios flag that might need to be set?

Mar 21 '06 #3
"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.

Mar 21 '06 #4
JustSomeGuy wrote:
Anyone know of an ios flag that might need to be set?

use std::getline(cin, mystring) to read an entire line.

Mar 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Witless | last post: by
16 posts views Thread by Basil Fawlty | last post: by
5 posts views Thread by Sinan Nalkaya | last post: by
reply views Thread by ward | last post: by
1 post views Thread by tikney5 | last post: by
4 posts views Thread by Paul David Buchan | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.