PDA

Click to See Complete Forum and Search --> : Program unlaods???


BloodMachine34
Jun 1st, 2001, 09:04 PM
Hi,
I'm currently learning C++ and I copied one simplest program from the book to my compiler, and then I compiled it.
#incude<iostream.h>
int main()
{
cout << "Hello World \n";
return 0;
}

After I ran the program, I noticed that it loads and automatically unlaods. How do I make it load, stay loads, and when I press the "x" button in the right hand corner, it will unlaod?
Thanks

Wynd
Jun 1st, 2001, 09:18 PM
#incude <iostream.h>
#include <stdio.h>
int main()
{
cout << "Hello World \n";
system("pause");
return 0;
}


This will pause the program until you press a key (oddly enough it says "Press any key to continue...").

chilibean
Jun 1st, 2001, 09:19 PM
There better ways to do this but this will work...
#include <iostream.h>
int main()
{
char nothing=0;
cout << "Hello World \n";
cin >> nothing;
return 0;
}

just hit any key on the keyboard and then enter to exit.


chilibean

chilibean
Jun 1st, 2001, 09:21 PM
That's the type of code I was thinking of and you beat me to it.;)

parksie
Jun 2nd, 2001, 06:29 AM
If it's in a console window you shouldn't use the X button to close it, because that can prevent it from cleaning up after itself (the compiler adds a lot more after your main() function has finished).