Sign in to follow this  

cin - back to basics

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this