Dev C++
is there any kind of hack or something I can use to keep the console window open other than adding code like system("PAUSE") and the like? I just find it annoying :(. I know at school somehow they got it to work (although it was a different compiler)
system("pause");
char x; std::cin >> x;
getch();
...they're all really hacks though, the correct way to do it is to open a console and run it in the console.
char x; std::cin >> x;
getch();
...they're all really hacks though, the correct way to do it is to open a console and run it in the console.
well like I know how to keep it open buy those means, I was just hoping that there was some compiler command or something. oh well heh
EDIT: fixed my terrible typing :D
EDIT: fixed my terrible typing :D
If you're running Windows, try this:
#include <windows.h>int main(int argg, char *argv[]){ ... while(!GetAsyncKeyState(VK_ESAPE) { // Will exit loop when escape-key is pressed } return 0;}
Quote:Original post by JoHnOnIzEr
is there any kind of hack or something I can use to keep the console window open other than adding code like system("PAUSE") and the like? I just find it annoying :(. I know at school somehow they got it to work (although it was a different compiler)
could this different compiler possibly be Visual C++? because Visual C++ inserts the code to leave it open i believe.
Hm.. Many IDEs contain launcher app, that wait, after your program has ended.
But, I think, that some quick batch file hack would be sufficent:
Save it as .bat and run this instead of your exe.
Oxyd
But, I think, that some quick batch file hack would be sufficent:
yourprogram.exepause
Save it as .bat and run this instead of your exe.
Oxyd
ok I'm new to C but i have done some pascal and basic and in turbo pascal inserting a readln statement at the end of your program stopped the console from closing and waited for some keyboard input before closing the console. i believe below is the C equivilant as it worked for me but i am new and i may be wrong. Below is a simple example program using this method.
============================================================
#include <stdio.h>
main()
{
int dummy;
printf ("hey is it working?");
dummy = getchar();
return 0;
}
=============================================================
the program waits at line 7 to get a value for dummy from the keyboard, just hit enter and the console closes.
============================================================
#include <stdio.h>
main()
{
int dummy;
printf ("hey is it working?");
dummy = getchar();
return 0;
}
=============================================================
the program waits at line 7 to get a value for dummy from the keyboard, just hit enter and the console closes.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement