cin.get() doesn't always work.

I've been working on a text-based RPG, and I use cin.get() a few times, with a "Press Enter to Continue" statement. I've used it a few times to break up the story, and it works fine there, but in the credits screen, before exiting, and in another place in the story, it didn't work. I've looked through my code, and I don't notice any differences between the instances where it works, and those where it doesn't.

if anyone needs it I could post the code.
Yeah, we'll need the code. Try posting one part where it does work and one where it doesn't.
works:
1
2
3
4
5
6
7
void story()
{
	cout << "\tblah\n\n";
	cout << "\tPress Enter to continue.";
	cin.get();
	cout << "\n\n\tYblah\n";
}


and doesn't work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int credits()
{
	cout << "**************************************************************\n";
	cout << "\t\t\tCredits\t\t\n";
	cout << "**************************************************************\n\n";
	cout << "\tblahblahblah\n";
	cout << "\tblahblahblah\n";
	cout << "\tblahblahblah";
	cout << "**************************************************************\n";
	cout << "\t\t   Thanks for playing!\n";
	cout << "**************************************************************";
	cin.get();
	
	exit(1);
}


it also didn't work in another void function.

edit: well, I've got a temporary fix, if I can't figure this out.

I added a wait function, using time.h, so the program automatically closes after a few seconds.
Last edited on
When you say it does not work, do you mean it is not waiting for input? If so, there is a very long article you can look into for answers and information:

http://www.cplusplus.com/forum/beginner/1988/
it waits for input at the instances that I said, but not for others.
Read the article, it has info on your problem. It's probably due to a stray '\n'...I'm not going into detail though...the article has it.
put a cin.sync(); above your cin.get();
Topic archived. No new replies allowed.