Problem With std::getline And C++
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
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!
[ 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 ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement