Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getline anomaly with Console app

Status
Not open for further replies.

gghorseman

Programmer
Feb 1, 2003
2
US
The following code demonstrates a problem I am having with getline(stream,var) in a Console app. The code should let you enter a string and when you press <ENter> , display it. In two different Unix systems it works as it should. In Visuall C++ ver 6.0, you have to press <Enter> TWICE before the input is selected and the string displayed. Anyone know why??

#include <iostream>
#include <string>
using namespace std;

int main(){
string Something(&quot;&quot;);
cout << &quot;Enter Something: &quot;;
getline(cin,Something);
cout << Something << &quot;|&quot; << endl;
return 1;
}
 
it's a small bug with the vc++ system, yeah, I've noticed this as well. you might try cin.getline(buffer) instead of the getline function, as this will fix the problem, but make sure to flush your input buffer before this, otherwise maybe you won't get to input anything at all.

-> cin.ignore(cin.rdbuf()->in_avail()) I believe is how to do this, but it's been a while since I've had to use getline functions, so :) The weevil of doooooooooom
-The eagle may soar, but the weasel never gets sucked up by a jet engine (Anonymous)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top