Jump to content

  • Log In with Google      Sign In   
  • Create Account

Question about std::cin


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1   Members   

459
Like
0Likes
Like

Posted 02 October 2012 - 04:44 PM

When I use std::cin to get input and enter a space after the input, it seems that the next cin statement is skipped. What is going on here and how do I get around this?
J.W.

#2   Moderators   

11526
Like
0Likes
Like

Posted 02 October 2012 - 04:50 PM

Are you using the >> operator to get input or one of the getline() functions?

#3   Members   

459
Like
0Likes
Like

Posted 03 October 2012 - 01:20 AM

the operator >>. Should I be using getline()?
J.W.

#4   Members   

220
Like
0Likes
Like

Posted 03 October 2012 - 01:23 AM

Yes

#5   Moderators   

11526
Like
1Likes
Like

Posted 03 October 2012 - 05:08 PM

It's not a matter of one being strictly better than the other. It's just that operator>> doesn't work how many people think it works. Specifically, after it reads what it wants to, it generally leaves stuff in the buffer that people don't think to get rid of before they do the next read. Depending on what types you're trying to read, doing so could be either very important or completely unnecessary.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.