Advertisement

Application can't seem to run..

Started by March 21, 2003 06:37 AM
7 comments, last by b0iNg 21 years, 7 months ago
After succesfully compiling my Hello.cpp file, I tried to run it. The tutorial says I should be able to see "Hello World!" however, I see some like a DOS window coming up and then disapearing before I can do anything. I heard it needs to me linked to something before it works...well, does Dev-C++ has a linker? Or else, where Can i get a linker? Thanks in advance!
Newbie Game Developer!
Add #include <stdlib.h> to the top of your source file.
Before return 0 at the end of your main function, add the line:

system ("pause");

Then recompile and execute.
Advertisement
Thanks alot MDI! I really appreciate that But can you also explain to me why those 2 lines are required? Thanks!
Newbie Game Developer!
Im guessing you use Dev-C++ or another compiler. The reason you need system(pause) is because when you display something, you are only displaying it one time, then never again (which could be less than a millisecond). If you pause the program, then the reader has enough time to read whatever is neccessary.

We must defeat the trolls!
Argh, we ARE the trolls!
KalvinB for moderator!
It also has to do with a default behaviour in Windows that makes it close DOS-Prompt programs when they have finished running. Since all your program is doing is writing to the prompt then exiting, the box disappears. Since it''s not exactly a CPU-taxing program, it can be opened and closed fast enough that you don''t see the results.

The system() function allows you to use any command that would work from the prompt. To see what I mean, open a DOS box and type "pause" (no quotes). Hit enter and it will look like exactly what that line of code did in your program. All other commands will work too, so with the system command you can call copy, dir, rename, etc.

-Auron
edit: Auron beat me and gave a better explanation.

More technically, when a program finishes execution, it exits (via the return from main()). Therefore, if you want it to persist, you have to delay its termination with a getch() or a system("pause").

[edited by - zealouselixir on March 21, 2003 12:06:30 PM]

[twitter]warrenm[/twitter]

Advertisement
I was about to post that as well. Everone is beating everyone today. Oh, If you want to use getch you must
#include <conio.h>
or else it won''t know what getch is.

--------------------------------------
I am the master of stories.....
If only I could just write them down...
I am the master of ideas.....If only I could write them down...
You can also open the dos prompt, move to the directory, and invoke the program from there instead of from windows explorer or whatever other graphical file browser you might use. This is the more ''unix like'' approach.
If you want more viewers for your website go to http://www.holyhits.com/?id=2078
It actually works. All you got to do is submit your link. Then get people to click your link and have then tell thier friends and so on. Its free and it works

This topic is closed to new replies.

Advertisement