Another "Press Enter to continue"

Jan 31, 2009 at 4:51pm
I know this has been asked a lot of times, but none of the answers seems to work.

The int main():
1
2
3
4
5
6
7
8
9
10
11
int main()
{
cout << "Hello Everyone" << endl;

cout << "Press enter to continue" << endl;

//What has to be placed here?

cout << "Hello World" << endl;
return 0;
}


How can I have the program stop until enter is pressed?

thx
Last edited on Jan 31, 2009 at 5:33pm
Jan 31, 2009 at 4:57pm
cin.ignore();
Jan 31, 2009 at 5:01pm
Jan 31, 2009 at 5:50pm
None of these seems to work.
Or maybe I'm just using all of them wrong.
Jan 31, 2009 at 7:22pm
Hehehe.
http://www.cplusplus.com/forum/beginner/1988/
Chew on it; it's a decent discussion/terrible argument, complete with a Linux fanboy and Patrick Stewart looking annoyed.
Jan 31, 2009 at 7:26pm
None of these seems to work.
Or maybe I'm just using all of them wrong.


I have no idea what you are doing wrong, but any one of them (appropriate to your OS) works just fine with the code you posted.

When programming, you absolutely must read all the fine print. You can't just glaze over it and say it doesn't work.

Post exactly what you are doing and we'll help you find your error.
Feb 7, 2009 at 9:21am
do you want it to wait specifically until enter is pressed or any key is pressed to continue?? I'm a complete beginner so I don't know if I'm stating something obvious but adding the line:

system("pause");

on windows will prompt a program to print, press any key to continue, on the console, but if you want it to specifically wait for the enter key only to continue then I'm not really sure. Perhaps if your desperate you could use an, if, or a, switch statement to make it continue only with the enter key but there MUST be an easier way than that. Like I said I'm really new to C++ but I really like this forum and I'd like to at least try to contribute to it.
Feb 7, 2009 at 9:35am
OK!! I'm sorry scratch that last post of mine I figured it out and it's just what demosthenes2k8 said in that reply. at //what has to be placed here?, type

cin.ignore(); or cin.get();

and the program will wait until enter is pressed, I'm still not sure what the difference between the two are but they work. And don't forget to make the program pause before, return 0;, unless your using an environment that does that for you like visual C++. but if you use dev-cpp like me, you gotta do that yourself.
Feb 7, 2009 at 11:14am
Or, you can stop being a lazy slob and just open a goddamn console.
Seriously, is that really harder than everything http://www.cplusplus.com/forum/beginner/1988/ has to offer?
Topic archived. No new replies allowed.