473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1778
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Witless | last post by:
This is 'supposed' to be a simple problem and shouldn't need too much time to solve :S Below is a function that works like this: int fn(int input) { int x=(input/8);
16
by: Basil Fawlty | last post by:
Hi everyone, I have an assignment, to create a simple VB program that computes the volume of a cylinder. The Form is pretty simple, it has a label and text box for base radius, another for height...
5
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
1
by: TopherB | last post by:
Hi, First let me say that my knowledge of HTML and Javascript is fairly limited. But I am stuck in a situation of trying to adapt a website's shopping cart to a new one. Here's the problem, the...
12
deephill
by: deephill | last post by:
hi i need form dependency. Can u check below code? <p>1. Are you married?</p> <p>
0
by: vidyamann | last post by:
Hello there, i have a problem with my php page. i have a form and different tabs on that. o the click of each tab, user will give his information in the text boxes. and for that i need a comman...
1
by: tikney5 | last post by:
I need to modify my current program so that is uses a class to store and retrieve the employees name, hourly rate, and number of hourse worked. Use a constructor to initialize the employee...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
4
by: Paul David Buchan | last post by:
Hello, I'm attempting to write a program to read in database files (.dbf). When I do it all as a single procedure in main, everything works. However, what I really want, is to pass the database...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.