Jump to content
  • Advertisement
Sign in to follow this  

cin - back to basics

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

Hey there. So, I never did fix a little annoyance I had with cin: the fact that if you have say
std::cin >> myInteger;

it just moves to the next line of the console with no complaints at all, and sits there waiting. I'm currently using some code to deal with unexpected input which goes:
char inputBuffer[20];
std::cout << "Enter price: ";
	valid = false;
	while (!valid)
		std::cin >> inputBuffer;
		price = (float)atof(inputBuffer);
		if (price > 0)
			valid = true;
			std::cout << "You must enter a positive non-zero number for price.  Please try again." << std::endl;
			std::cout << "Enter price: ";

but this doesn't solve the bug outlined above. Does anyone have a workaround?

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!