473,473 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1779
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.