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

Home Posts Topics Members FAQ

getline(cin, zips) skips fist input before a while loop in function

1 New Member
i typed a function to enter data into a file to be recalled later, now i have done something here and as soon as this function begins it skips the first 'zips' getline and makes it a blank space and goes directly to 'city' - someone please tell me what the hell happenned here - g'day - mark


void addData()
{
string zips = "";
string city = "";

ofstream outFile;

outFile.open("citiesandzips.txt");

if(outFile.is_open())
{
cout << "Enter ZIP Code (X to stop): " << endl; ///this is my problem - this bastard doesnt take data it automatically fills out as a blank space
getline(cin,zips);
transform(zips.begin(), zips.end(), zips.begin(), toupper);


while (zips != "X")
{
cout << "Enter City: " << endl;
getline(cin,city);

outFile << zips << '#' << city << endl;

cout << "Enter ZIP Code (X to stop): ";
getline(cin,zips);

transform(zips.begin(), zips.end(), zips.begin(), toupper);

}
outFile.close();
}
else
cout << "The file could not be opened." << endl;
}
Jul 22 '06 #1
1 3110
Banfa
9,065 Recognized Expert Moderator Expert
Shouldn't this

getline(cin,zips);

be this

cin.getline(zips, sizeof zips);
Jul 22 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Vikram | last post by:
Hi, I don't remember if it happened previously, but nowadays I'm having problem with using cin.getline function and cin>> function simultaneously. I have Visual Studio 6. If I use cin.getline...
5
by: Danny Anderson | last post by:
Hola- I didn't get any responses on a previous post, so I am trying to reword my problem and post compile-able code that exhibits the behavior I am describing. On the second iteration of the...
3
by: Shane | last post by:
So it's been a while since I've done anything in C++, but I thought I could grab cin >> input; and it would go into string input, even if what's coming in happens to be 3 words separated by...
4
by: Tcc | last post by:
Hi all, I have a question about using the function getline().. e.g. I have defined a structure: struct s { string *a; Queue *b; }; then in my main function:
1
by: Peter van der Goes | last post by:
Had this question from a student and confirmed the behavior in VC++ .NET 2003: > cout << "Please enter your name: "; > getline(cin,myName); > cin.ignore(100,'\n'); > > The only problem with...
4
by: PulsarSL | last post by:
Hi I'm working on improving the "Simpletron" computer described in Deitel & Deitel's "C++ How to Program" 3rd edition. Check out http://www.lehigh.edu/~ejk0/smlspec.pas for a description if...
9
by: CyBerFirEZ | last post by:
This is the second time I am experiencing a problem with getline. I've used it before successfully, but I dont know what I'm doing wrong here. Here is the code where the problem is: if (a...
5
by: erictheone | last post by:
so here is my code. My getlines for the strings keyword and phrase at lines 44 and 79 respectively don't work. Please help!!! #include <cstdlib> #include <string> #include <iostream> #include...
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
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
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,...
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: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.