little help plz :)

when any console application finishes in c++ it types "press any key to continue ... " and it waits me to press any key to close
what should i do if i want to colse my console without showing this phrase and without press any key to close it thnx in advace
Last edited on
What IDE are you using? You can always run the program from the command line.
read this:

http://www.cplusplus.com/forum/beginner/1988/


This thread is stickied because it is such a common problem.
I use visual studio 2012 i couldn't find what i want
i want in my program when the whole code finishes,it closes from its self withiut showing me "press any key to continue ... "
The usual problem is that the console program closes too soon, before the user has any chance to read what is on the screen.

If the program stays open with the message "press any key to continue ... " even when you run it from the command line, it must be because there is some code in the program causing that to happen. All you need to do is to remove that code, and recompile.

But if you run the program from within the IDE, the message could come from the IDE, rather than the program itself.
Last edited on
my code works correctly i want to close it without this phrase
"press any key to continue"
how can prevent this from showing ??
Does your code have something like
 
    system("pause");

If so, remove that line.

(It's not a case of preventing anything. Rather it's a matter of removing the part where it is deliberately caused.)
Last edited on
no it haven't
did you understand exactly what i want ??
Yes. The message comes from either:
• some code in the program which caused the message to appear
or
• something in the IDE or the way you are running the program, which produces the message.

By default, a program like this will open and close instantly, with no message:
1
2
3
4
5
6
int main()
{


    return 0;
}


Last edited on
my code looks like that and this message appears at the end of it
Ok. That makes things clearer.

May I ask, how do you run your program? is it from within the development environment? Or do you close down the compiler and just run the executable program directly?

Actually, since I don't use visual studio, there may be some configuration setting that I'm not aware of.
Last edited on
i run my prog by pressing ctrl+f5 ... and it closes when the code finishes
Well, I'm not using visual studio, so I'm giving second-hand information here. But it seems that pressing ctrl-f5 is the cause of the "press any key" message.

But, as I suggested previously, you can close the visual studio program and directly run your program. That should get rid of the unwanted message. That is, double-click on the executable as you would any other program. The executable will probably reside within a sub-folder, it might have a name such as release or debug or something like that.
Last edited on
if you didnt put "press any key to continue ... " in your program, then it is the result of the IDE, not your program. It is for development use, same as some IDE's show execution time, etc. Running your program from terminal or command prompt (if your on windows) will execute your program without the IDE's extra info.

for example in linux:
sudo vim main.cpp (using vim to create the file)
g++ main.cpp -o main (compiles main.cpp to main)
./main (runs main in same directory)

This method is terminal only, no IDE, so therefore no IDE extra info is displayed along with the program. And i am sure windows is similar just different commands
Last edited on
Topic archived. No new replies allowed.