Problem With std::getline And C++

Started by
2 comments, last by kuphryn 22 years, 4 months ago
Hi, I find there is a slight inconvenience with the std::getline function in C++. Here is an example: ----------------------------------------------------------- #include using std::cin; using std::cout; using std::endl; using std::getline; #include using std::string; int main() { string strTemp; cout << "Enter a sentence: "; getline(cin, strTemp); cout << "\nYou entered: " << strTemp << endl; return 0; } ----------------------------------------------------- If you run the code above, and hopefully I did not leave anything out, out will find that after you entered a sentence and press Enter, the "cursor" will go to the next line, but the program does not move onto "You have entered: " until you press Enter the second time. In other words, I have had problems with the getline function in term of having to press Enter twice to get it to move onto the next algorithm. I have tried for example: getline(cin, strTemp, ''\n''); It has the same effect. Is there a way to get around having to press Enter twice? Thanks, Kuphryn
Advertisement
It is a known bug in the STL implementation that ships with MSVC. You can find the fixes here.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
Do they not read my signature? First link on the left

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
Nice!

zen posted the same message at cprogramming with a link to Microsoft''s website.

Thanks,
Kuphryn

This topic is closed to new replies.

Advertisement