getline with cin problem -- multiple returns needed

C

Chris

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?
 
M

Marcus Kwok

Chris said:
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";
}
 
D

David Harmon

On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
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/
 
C

Chris

David said:
On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"


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.
 
J

Jim Langston

Chris said:
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.
 
C

Chris

Jim said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top