Advertisement

Console Closing

Started by January 28, 2002 11:25 PM
5 comments, last by Anidem 22 years, 10 months ago
How can I keep the console from closing, ii''m using c++.
What console are you referring too? bash, ms-dos, csh, tcsh, etc.
Advertisement
the cmd console, which i guess is ms-dos
Ok, so I guess your using Windows. Well, the easiest way I suppose is to use getchar to wait for a key to be pressed; when the key is pressed the program exits. For example:
  #include <stdio.h>int main(){    //  Some code    //  Wait for some input from the keyboard    getchar();    //  Exit the program by closing the console    return 0;  
You could always inlude conio.h and put getch() at the end of your code

    #include <conio.h>void main(){   // do stuff   getch();}    


EDIT - Whoops. Looks like Floppy beat me too it. They both basically do the same thing. Have fun

Edited by - Big Sassy on January 29, 2002 1:09:24 AM
thanks
Advertisement
I prefer

#include <stdlib.h>int main(){  system("PAUSE");  return 0;} 

This topic is closed to new replies.

Advertisement