Question:
How do I keep the output screen up when compiling with Dev-C++?
Eric M
2009-08-18 19:31:50 UTC
Ok, so I'm just starting to learn about the C programming language, and I'm practicing programming with C in the Dev-C/C++ Compiler. Unfortunately, I don't know what line of code is necessary to keep the output screen up. If someone could give me a line of code that requires me to hit the escape key to terminate the execution that would be lovely.

Thanks :).
Four answers:
jplatt39
2009-08-18 22:42:55 UTC
Three ways, of course. Especially since you are learning C, not C++ one way is to use the system() call in stdlib, which is mentioned above but wortth looking up. Doing system("pause"); calls the Pause.exe program which prints the line "Press any key" then does nothing until you do.



conio.h has getch() which you can use to demand input -- just do getch(); and it usually compiles and runs. It will do nothing until you press any key. Same thing with no message, unless you write it to the screen.



The easiest way is to compile your program normally but keep a command shell open and use that to run your exe file. The reason the output screen closes when it finishes is because it is open ONLY to run your program. If you keep an output screen open and run your program from within it it won't close and you shouldn't have a problem.
?
2009-08-19 03:03:05 UTC
type in:



int x;

std::cin >> x;

return 0;





or if you have "using std::cin" at the top of your program, you can just type



int x;

cin >> x;

return 0;



now it will stay up until you type in a value and press enter, which will commence the program. or you can always just use pause. oh and use a varible that is not in use. i used x for an example.
tbshmkr
2009-08-19 04:52:23 UTC
Add this to your C++ programs

Press [ENTER] to end.

=



#include



//Last 2 lines

cout << endl <<"Press [ENTER] to end. " << flush;

cin.ignore(numeric_limits ::max(), '\n' );

= = =

//Example

#include

#include

using namespace std;



int main()

{

cout << "Hello World" << endl;

cout << endl <<"Press [ENTER] to end." << flush;

cin.ignore(numeric_limits ::max(), '\n' );

return 0;

}
ungkog
2009-08-19 02:43:14 UTC
put this line of code just before the RETURN



system ("PAUSE");


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...