Sign in to follow this  

Dev C++

This topic is 4859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:


yourprogram.exe
pause


Save it as .bat and run this instead of your exe.

Oxyd

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this