473,387 Members | 1,453 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.

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 2412
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...

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.