Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > getline with cin problem -- multiple returns needed

Reply
Thread Tools

getline with cin problem -- multiple returns needed

 
 
Chris
Guest
Posts: n/a
 
      10-19-2006
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?

 
Reply With Quote
 
 
 
 
Marcus Kwok
Guest
Posts: n/a
 
      10-19-2006
Chris <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
 
 
 
David Harmon
Guest
Posts: n/a
 
      10-19-2006
On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
<(E-Mail Removed)> wrote,
>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/

 
Reply With Quote
 
P.J. Plauger
Guest
Posts: n/a
 
      10-19-2006
"David Harmon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
> <(E-Mail Removed)> wrote,
>>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


 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      10-19-2006

David Harmon wrote:
> On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
> <(E-Mail Removed)> wrote,
> >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.

 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      10-19-2006

P.J. Plauger wrote:
> "David Harmon" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> > On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
> > <(E-Mail Removed)> wrote,
> >>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.

 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      10-19-2006
"Chris" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>
> P.J. Plauger wrote:
>> "David Harmon" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>
>> > On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
>> > <(E-Mail Removed)> wrote,
>> >>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.


 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      10-20-2006

Jim Langston wrote:
> "Chris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> >
> > P.J. Plauger wrote:
> >> "David Harmon" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >>
> >> > On 19 Oct 2006 08:09:33 -0700 in comp.lang.c++, "Chris"
> >> > <(E-Mail Removed)> wrote,
> >> >>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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with cin.getline() bintom C++ 4 05-30-2010 08:55 AM
newbie problem with cin and getline Devendra_Vidhale C++ 20 07-19-2007 08:19 AM
cin.getline() problem Markus C++ 11 09-04-2006 01:03 AM
cin and cin.getline() Aleander C++ 5 03-06-2005 03:57 PM
Problem with cin.getline(); Poof C++ 1 07-11-2003 01:14 PM



Advertisments