Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Problem With std::getline And C++

This topic is 6126 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!