"Press any key to continue..."

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
Nope. That's a function of your IDE or shell you are running the program in.
Okay, thanks I guess... :(
You might consider writing code to display your own message and handle your own input to exit however.
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.
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.
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?
The function itself isn't; it's a part of cstdlib, but most of the stuff you put into it is OS-specific.

-Albatross
system() ? Oh, this is bad.
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
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.
@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.