Jump to content
  • Advertisement
Sign in to follow this  
JoHnOnIzEr

Dev C++

This topic is 5220 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
Advertisement
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
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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!