Jump to content
  • Advertisement

Archived

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

MessageBox

Fun with streams

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

int main(void)
{
	int temp;

	cout<<"Press a key to continue"<<endl;
	getchar();

	cout<<"Again"<<endl;
	getchar();

	cout<<"And Again"<<endl;
	getchar();

	cout<<"O.K. now for a change, press a key"<<endl;
	cin>>temp;

	cout<<"Why didn''t input get blocked on this line?"<<endl;
	getchar();

	cout<<"End"<<endl;
        return 1;
}
Can anybody tell me why getchar() doesn''t block input after using cin, and how to remedy the situation

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
The cin is probably leaving the \n inside the input stream (which is put in when you press enter), and so the getchar() just retrieves the \n and doesnt block

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!