"Press any key to continue..."

Feb 13, 2011 at 1:22am
Hi, I'm new to C++ and I noticed that after the program is finished running it will display the phrase, "Press any key to continue..." I was simply wondering if it is possible to change this phrase to same something else, like "Press any key to exit." Which seems more fitting to me. Is this possible, and if so how do i do it? Thanks in advance.
Last edited on Feb 13, 2011 at 3:29am
Feb 13, 2011 at 1:24am
Nope. That's a function of your IDE or shell you are running the program in.
Feb 13, 2011 at 1:50am
Okay, thanks I guess... :(
Feb 13, 2011 at 3:24am
You might consider writing code to display your own message and handle your own input to exit however.
Feb 13, 2011 at 4:14am
It depends on your compiler. Most compilers will give you that message if you use system("pause"). You can make your own by using cin.ignore(100) and cout whatever you want.
Feb 13, 2011 at 4:28am
What is done by system() is it issues a command to the operating system just as if you had typed it into a shell. If you use system() you must be careful that you handle the differences between the systems you use it on. For something this simple, use the normal i/o facilities to display a message.
Feb 13, 2011 at 4:56am
correct me if I'm wrong, but isn't system() OS specific? what I'm getting at is if i used for example system("cls"), and then tried to run the program on a non-windows/dos machine, it would'nt work...right?
Feb 13, 2011 at 5:09am
The function itself isn't; it's a part of cstdlib, but most of the stuff you put into it is OS-specific.

-Albatross
Feb 13, 2011 at 12:58pm
system() ? Oh, this is bad.
Feb 13, 2011 at 1:09pm
I think its possible... correct me if im wrong;

for example you can have a function:
1
2
3
4
5
6
void main(){
//codes here
cout << "Press anykey to exit.";
cin.ignore();
cin.get();
}


in this way, it will somehow make a program look like it is the message before exiting a certain program
Feb 13, 2011 at 2:03pm
There's a whole article on this:
http://www.cplusplus.com/forum/articles/7312/

If you didn't put the message there to begin with, then it is, as firedraco said, something your IDE is doing for you so that you can see your program's output before the console window disappears. This is a typical thing for Windows-specific compilers, AFAIK. You'll have to run your program directly (instead of from the IDE) to see it work properly.

Hope this helps.
Feb 13, 2011 at 2:52pm
@markXD07: You are technically correct, it's proper to have the main function return an integer because the OS expects something indicating success or failure, Zero indicates success hence "return 0;" at the end of most programs on this site.
Topic archived. No new replies allowed.