Discussion:
[std::getline] Avoid having to hit <Enter> twice, How to?
(too old to reply)
Anand Hariharan
2004-10-11 17:31:22 UTC
Permalink
Say I have this really simple code:

<code>
#include <string>
#include <iostream>

int main(void)
{
std::string Name;
std::cout << "Please enter your name: ";
std::getline(std::cin, Name);
std::cout << "Hello " << Name << std::endl;
return 0;
}
</code>

When executing the above compiled code, I have to hit the <Enter> key
TWICE, once after entering my name, and another in a line all by
itself.

Is this a library QoI issue (WinXP, VC6 SP6)
or is there something about getline (or iostreams in general) that I
am not aware of?

thank you & best wishes,
- Anand Hariharan
Aggro
2004-10-11 17:34:11 UTC
Permalink
Post by Anand Hariharan
Is this a library QoI issue (WinXP, VC6 SP6)
or is there something about getline (or iostreams in general) that I
am not aware of?
Known bug in VC6. There is also fix to it, if you search for previous
answers with searchwords like getline, enter and twice, you should find
some info how to fix that.
Gary Labowitz
2004-10-11 23:17:04 UTC
Permalink
Post by Aggro
Post by Anand Hariharan
Is this a library QoI issue (WinXP, VC6 SP6)
or is there something about getline (or iostreams in general) that I
am not aware of?
Known bug in VC6. There is also fix to it, if you search for previous
answers with searchwords like getline, enter and twice, you should find
some info how to fix that.
Also, Dinkumware.com has a fix on its VC6.0 bug list with fixes.
--
Gary
Mike Wahler
2004-10-11 23:24:42 UTC
Permalink
Post by Gary Labowitz
Post by Aggro
Post by Anand Hariharan
Is this a library QoI issue (WinXP, VC6 SP6)
or is there something about getline (or iostreams in general) that I
am not aware of?
Known bug in VC6. There is also fix to it, if you search for previous
answers with searchwords like getline, enter and twice, you should find
some info how to fix that.
Also, Dinkumware.com has a fix on its VC6.0 bug list with fixes.
See my reply for the URL.

-Mike
Mike Wahler
2004-10-11 18:35:27 UTC
Permalink
Post by Anand Hariharan
<code>
#include <string>
#include <iostream>
int main(void)
{
std::string Name;
std::cout << "Please enter your name: ";
std::getline(std::cin, Name);
std::cout << "Hello " << Name << std::endl;
return 0;
}
</code>
When executing the above compiled code, I have to hit the <Enter> key
TWICE, once after entering my name, and another in a line all by
itself.
Is this a library QoI issue (WinXP, VC6 SP6)
Yes.
Post by Anand Hariharan
or is there something about getline (or iostreams in general) that I
am not aware of?
See http://www.dinkumware.com/vc_fixes.html

Search for "Fix to <string>"

You might also want to apply the other fixes cited on that page,
or perhaps upgrade to the newer version of VC++.

-Mike
Anand Hariharan
2004-10-12 21:55:59 UTC
Permalink
(...)
Post by Mike Wahler
Post by Anand Hariharan
When executing the above compiled code, I have to hit the <Enter> key
TWICE, once after entering my name, and another in a line all by
itself.
Is this a library QoI issue (WinXP, VC6 SP6)
Yes.
(...)
Post by Mike Wahler
See http://www.dinkumware.com/vc_fixes.html
Search for "Fix to <string>"
You might also want to apply the other fixes cited on that page,
or perhaps upgrade to the newer version of VC++.
-Mike
Thank you, Mike.

* The behaviour is observed (as I indicated above) even on VC with
SP6. Am afraid, I am not in a position to move to .NET or some such
version that (I am told) has a more conforming compiler.

* That web-page says that the fix for the problem requires one to
update the <istream> header. I grepped for the all the identifier
names both in istream, istream.h and all the headers in the include
directory, but could not find a single file that had all the
identifiers. The ISTREAM.H header contains a (seemingly) simplistic
definition of getline.

In any case, thanks for reassuring that it is a QoI issue.

best wishes,
- Anand
Karl Heinz Buchegger
2004-10-13 09:44:27 UTC
Permalink
Post by Anand Hariharan
* That web-page says that the fix for the problem requires one to
update the <istream> header. I grepped for the all the identifier
names both in istream, istream.h and all the headers in the include
directory, but could not find a single file that had all the
identifiers. The ISTREAM.H header contains a (seemingly) simplistic
definition of getline.
The simplest way is as follows.
In a source window write:

#include <istream>

Then position the caret in this line, right mouse button, and select
'Open document <istream>'

VC++ will search the file for you and open an edit window.
Apply the fixes and save.
--
Karl Heinz Buchegger
***@gascad.at
Continue reading on narkive:
Loading...