-
my dos closes at once
I downloaded a compiler bloodsheft or something and copied and pasted some tutorial stuff into it. "Hey you im alive and oh hello world" :)
well i did that it all worked but when i open the .exe it opens for a milisecond and then closes again?
I can read the sentence for a sec so i did that right
But what's up?
-
Go to the C board. All your questions will be answered.
ps::system("PAUSE")
should work.
-
#include <iostream.h>
int main()
{
cout<<"HEY, you, I'm alive! Oh, and Hello World!";
return 0;
}
where do i put that then? p
-
You printed a string and then instructed the system to "return" to the calling environment, which in this case would be the OS I suppose, and so to answer your question, before you call return.
-
this always works, i use DEV all the time
#include <ioststream.h>
#include <stdlib.h>
int main () {
cout<<"Hello World!";
return 0;
}
always be sure to include that stdlib.h ..... i read about it in the Dev C++ help file :)
-
Like I previously posted a couple of days ago:
return 0; at the end of main should freeze the DOS window, but in some cases in doesn't.
What you should do in order to see the output is open a DOS window and run the program from inside the DOS prompt. The difference is:
The way you do it - you open a DOS exe in Windows environment, it runs, it finishes running, Windows closes the DOS windows for you.
The way you should try - open a DOS windows, go to the directory where the executable you want to run is stored, run that exe. In this case the program runs and stops running inside the DOS window that is under your control (since you opened it) and Windows cannot close it unless you tell it (or Windows crashes, whichever comes first). :D
Hope this helped.
-
I'm a rookie at this however is
int main()
{
cout << "Hello world";
cout<< " Press any key to return to dos";
getchar();
return 0;
}
a stupid solution??
-
This will do the trick for this specific purpose. However, if you ran it from a regular DOS window, it will cause you to press a key to exit it whereas it should have executed normally. After me having said this I only want to add that the implementation is always up to the programmer himself to be decided.
Cheers.