Here is what I do to make it so you have to press a key to continue.
1 2 3 4 5 6 7 8 9 10 11 12
#include<iostream> //for cout
#include<conio.h> //for getch()
usingnamespace std;
int main(void)
{
int k=0; //variable
cout << "press something anything i need to be free" << endl;//message to tell the user to press a key to continue
k=0;while(k==0) k=getch(); //pausing sequence
cout << "thanks" << endl; //something afterwards to prove it works
return (0);
}
Also, never use system("pause"); or any system command because... well... just read this article.
"Open a terminal/command prompt change directory to where the executable is and run it."
thank you that is really wonderful idea and it works . Is there a way to do it automatically without having each time to change to where the executable is then running it ???
You can probably set up your IDE to do that automatically with some custom debug/run options. I'm not sure where those would be in DevC++ though, probably in some project/program properties window.
Also, consider upgrading to a more recent IDE like wxDevC++ (or whatever is the newest).
@thecrazedone126 your solution is not the best. First, why to declare new, unused variable?
You can do sth like that: while(true) getch();
Second, those kind of loops are horrible. They run all the time. It uses all processor resources it can. It's much better to use std::cin.get();. It doesn't make that ugly loop. Use it once normally or twice if there was std::cin >> something; before, as it has to catch enter key, that was not caught by std::cin object.
dilver, you can also compile it as release. That "press any key to continue" is code added to the end of the run by the compiler in a debug compilation.