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("c itiesandzips.tx t");
if(outFile.is_o pen())
{
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,zip s);
transform(zips. begin(), zips.end(), zips.begin(), toupper);
while (zips != "X")
{
cout << "Enter City: " << endl;
getline(cin,cit y);
outFile << zips << '#' << city << endl;
cout << "Enter ZIP Code (X to stop): ";
getline(cin,zip s);
transform(zips. begin(), zips.end(), zips.begin(), toupper);
}
outFile.close() ;
}
else
cout << "The file could not be opened." << endl;
}
1 3132 Banfa 9,065
Recognized Expert Moderator Expert
Shouldn't this
getline(cin,zip s);
be this
cin.getline(zip s, sizeof zips);
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 function at
first and then I use the cin>> function then the next time
cin.getline function does not work.
|
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 loop below, the file opened is the default
(which in this case is ".csv", which makes a 'hidden' file for Linux
folk). The step that prompts for a file name step is skipped completely.
Why? Is this a cin issue or does it have something to do with...
|
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 spaces. I don't want to use c strings, I want
to use std::string.
So imagine the code
|
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:
|
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 this is I have to press "enter"
> twice before the input is accepted. Is there a way to
> eliminate the need for twice pressing "enter"?
| |
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 you're
curious.
I'm trying to add my own opcodes for string input/output using the
string type from string.h
|
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 == 6)
{
string f;
int g;
cout << "Enter the message to display at the end of the countdown:" << endl;
|
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 <fstream>
using namespace std;
string removeAllWhite( string eric)
{
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |