473,287 Members | 1,395 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,287 software developers and data experts.

getline with cin problem -- multiple returns needed

Running into a problem on Windows. This code

std::string randomStuff;
std::getline(std::cin, randomStuff);

works on unix, but on windows, it requires the user to hit the enter
key *twice* before it continues past the getline. I tried changing the
getline to

std::getline(std::cin, randomStuff, '\n');

but that didn't help. Any ideas?

Oct 19 '06 #1
7 2409
Chris <ch***************@gmail.comwrote:
Running into a problem on Windows. This code

std::string randomStuff;
std::getline(std::cin, randomStuff);

works on unix, but on windows, it requires the user to hit the enter
key *twice* before it continues past the getline. I tried changing the
getline to

std::getline(std::cin, randomStuff, '\n');

but that didn't help. Any ideas?
Please post a complete and minimal program that demonstrates your
problem. For what it's worth, this program works fine on my system
(Windows XP SP2, compiled with VS .NET 2003 SP1):
#include <iostream>
#include <string>

int main()
{
std::cout << "Enter some text:\n";

std::string randomStuff;
std::getline(std::cin, randomStuff);

std::cout << "\nYou entered:\n\"" << randomStuff << "\"\n";
}

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Oct 19 '06 #2
On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
<ch***************@gmail.comwrote,
>Running into a problem on Windows. This code

std::string randomStuff;
std::getline(std::cin, randomStuff);

works on unix, but on windows, it requires the user to hit the enter
key *twice* before it continues past the getline.
I don't believe you. It is something else you haven't shown us that
causes your problem.

This issue is covered in Marshall Cline's C++ FAQ. See the topic
"[5.8] How do I post a question about code that doesn't work
correctly?". It is always good to check the FAQ before posting.
You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/

Oct 19 '06 #3
"David Harmon" <so****@netcom.comwrote in message
news:45****************@news.west.earthlink.net...
On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
<ch***************@gmail.comwrote,
>>Running into a problem on Windows. This code

std::string randomStuff;
std::getline(std::cin, randomStuff);

works on unix, but on windows, it requires the user to hit the enter
key *twice* before it continues past the getline.

I don't believe you. It is something else you haven't shown us that
causes your problem.
He might be right, if he's using an unpatched V6. See:

http://www.dinkumware.com/vc_fixes.html

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Oct 19 '06 #4

David Harmon wrote:
On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
<ch***************@gmail.comwrote,
Running into a problem on Windows. This code

std::string randomStuff;
std::getline(std::cin, randomStuff);

works on unix, but on windows, it requires the user to hit the enter
key *twice* before it continues past the getline.

I don't believe you. It is something else you haven't shown us that
causes your problem.
I assure you, my pants are not on fire.

Oct 19 '06 #5

P.J. Plauger wrote:
"David Harmon" <so****@netcom.comwrote in message
news:45****************@news.west.earthlink.net...
On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
<ch***************@gmail.comwrote,
>Running into a problem on Windows. This code

std::string randomStuff;
std::getline(std::cin, randomStuff);

works on unix, but on windows, it requires the user to hit the enter
key *twice* before it continues past the getline.
I don't believe you. It is something else you haven't shown us that
causes your problem.

He might be right, if he's using an unpatched V6. See:

http://www.dinkumware.com/vc_fixes.html

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
This sounds very likely. We are using VC6. Will investigate further.

Oct 19 '06 #6
"Chris" <ch***************@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>
P.J. Plauger wrote:
>"David Harmon" <so****@netcom.comwrote in message
news:45****************@news.west.earthlink.net.. .
On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
<ch***************@gmail.comwrote,
Running into a problem on Windows. This code

std::string randomStuff;
std::getline(std::cin, randomStuff);

works on unix, but on windows, it requires the user to hit the enter
key *twice* before it continues past the getline.

I don't believe you. It is something else you haven't shown us that
causes your problem.

He might be right, if he's using an unpatched V6. See:

http://www.dinkumware.com/vc_fixes.html

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com

This sounds very likely. We are using VC6. Will investigate further.
If you are still using VC6 run, don't walk, to the nearest computer store
and pick up a newer compiler (or download a free version).

I used to use VC6 and it just has so many problems because I understand it
preceeded the current standard.
Oct 19 '06 #7

Jim Langston wrote:
"Chris" <ch***************@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...

P.J. Plauger wrote:
"David Harmon" <so****@netcom.comwrote in message
news:45****************@news.west.earthlink.net...

On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
<ch***************@gmail.comwrote,
Running into a problem on Windows. This code

std::string randomStuff;
std::getline(std::cin, randomStuff);

works on unix, but on windows, it requires the user to hit the enter
key *twice* before it continues past the getline.

I don't believe you. It is something else you haven't shown us that
causes your problem.

He might be right, if he's using an unpatched V6. See:

http://www.dinkumware.com/vc_fixes.html

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
This sounds very likely. We are using VC6. Will investigate further.

If you are still using VC6 run, don't walk, to the nearest computer store
and pick up a newer compiler (or download a free version).

I used to use VC6 and it just has so many problems because I understand it
preceeded the current standard.
Unfortunately, this is the "official compiler" for our product at work.
Companies I work at seem to get frozen on old compilers because they
are scared of upgrading and having to regression test.

Oct 20 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: John | last post by:
Hello all, I am trying to read in lines into a buffer from a file. Normally I would do this very low-level, but I have come to the conclusion I must stop doing everything the hard way. So, I...
15
by: Christopher Benson-Manica | last post by:
The dumb-o-meter's pegging out today... What, if anything, is wrong with the following code? std::ifstream f( "myfile.txt" ); if( !f ) { cerr << "Couldn't open file\n"; } while( getline(f,s)...
10
by: Skywise | last post by:
I keep getting the following error upon compiling: c:\c++ files\programs\stellardebug\unitcode.h(677) : error C2664: 'class istream &__thiscall istream::getline(char *,int,char)' : cannot convert...
6
by: JustSomeGuy | last post by:
Getline has a delimiter character parameter that is used to say when input should stop. (std::cin.getline) However what do you do if you have multiple conditions/character on which you wish to...
2
by: Peter Gordon | last post by:
Is using getline with a fstream reference covered in the standard? I have three C++ compilers on my system. Two of them compile the code below without warnings. The third returns the following...
6
by: Dave | last post by:
In .Net 2003 if a line, read from a text file is larger than a size parameter, the ifstream getline(buff, sze) put the file pointer to the EOF, so next peek() returns EOF. I saw this problem...
2
by: Mark P | last post by:
Consider the following snippet of code to read lines from a text file: ifstream file_stream( "some_file.txt"); string read_line; while( file_stream) { getline( file_stream, read_line); } ...
6
by: ankit.kumar.agarwal | last post by:
I am facing a problem with getline I am reading a text file with a getline function the lines can have '|' as separator. everything works OK but in case if i have 2 delimitors in file '234||...
13
by: Rosario | last post by:
do you like the "GetLine_m" function i have written today? How many errors do you see? i have try only the option for to load the all file in a string not the option to load a line "\n" ended so...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.