Jump to content
  • Advertisement
Sign in to follow this  
Daher_Q3A

std::cin operator

This topic is 4993 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

the code: std::cin >> c; requires to type a char then press enter. in VC2003.net it looks like I should use std::cin >> c >> c2; to hold the enter key in c2. Anybody knows whats wrong? I have like: std::cin >> c; // do something std::cin >> c; the second time was skipped everytime... Using msvc 2003 .net - In debug mode, it happens correctly that operator >> ignores the white spaces, but in release mode it freaks out... can anybody confirm?

Share this post


Link to post
Share on other sites
Advertisement
First and foremost, std::cin isn't an operator, it's a global variable. [grin] Now, a carriage return is a perfectly valid character, which isn't discarded when you just do character-by-character input. So if you type a character and then return, you've indeed got to get rid of both the character and the newline.

Have a look at the std::ws manipulator, or at std::cin's ignore member function. In particular, std::cin.ignore(std::numeric_limits<int>::max(), '\n'); will ignore all the characters up to and including the first newline encountered (i.e. it will discard the remainder of the line and eat up the newline). The std::numeric_limits trait template class can be found in <limits>

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!