#include <iostream.h>
void main()
{
cout <<"Hello World!\n";
return 0;
}
As soon as I run it, a DOS window pops up. Then goes away giving me zero time to see it.
I'm using Dev-C++ to learn befor I make an investment in anything. Any help you could provide would be greatly appreciated.
- Scott_U
Edited by - Scott_U on March 1, 2002 2:42:10 PM
Newbie In Need Of Help...
This is going to sound completely rediculous. I'm having trouble with the "Hello World" program.
this is possibly THE most asked questions... search the forums...
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Oh, sorrry, I searched using the search option but I couldn''t find what I was looking for. My apologies...
March 01, 2002 01:53 PM
Either run it from the windows console to keep the output on screen, or put something along the lines of:
getch(); (included from conio.h) which waits for a character to be inputted before continuing
while(!kbhit()); (included from conio.h) which loops until a key is pressed
system("pause"; (included from stdlib.h) which essentially executes the pause command in the console (which waits until a key is pressed before continuing...)
char buf[2];
cin >> buf; which simply waits for input before continuing
Sleep(1000); (included in windows.h) which waits 1000 ms before continuing
…before the return 0; which exits the program. You really just need to have some type statement that will halt the program''s execution so you can see the output. (Note that much of the above is not ANSI) Hope this helps!
getch(); (included from conio.h) which waits for a character to be inputted before continuing
while(!kbhit()); (included from conio.h) which loops until a key is pressed
system("pause"; (included from stdlib.h) which essentially executes the pause command in the console (which waits until a key is pressed before continuing...)
char buf[2];
cin >> buf; which simply waits for input before continuing
Sleep(1000); (included in windows.h) which waits 1000 ms before continuing
…before the return 0; which exits the program. You really just need to have some type statement that will halt the program''s execution so you can see the output. (Note that much of the above is not ANSI) Hope this helps!
The reason is it''s a console program. If you run it in DOS (for windows, other systems are different), it won''t close on you.
BTW, since main() is void, you dont need the
return 0;
line. It dosent really mater though.
"cogito, ergo sum" -Descartes
return 0;
line. It dosent really mater though.
"cogito, ergo sum" -Descartes
"cogito, ergo sum" -Descartes
I'm not sure where you got this code from, but there are several mistakes. The canonical C++ form would look like this:
If you want to catch the output before the debug console closes, whack a breakpoint on the closing brace of main.
--
You see some pale bulbous eyes staring at you.
Edit - add comments.
Edited by - SabreMan on March 1, 2002 8:25:01 PM
#include <iostream> // correct headerint main() // main always returns int. always!{ std::cout << "Hello World!\n"; // qualify by namespace} // no need for return 0 - it's implied
If you want to catch the output before the debug console closes, whack a breakpoint on the closing brace of main.
--
You see some pale bulbous eyes staring at you.
Edit - add comments.
Edited by - SabreMan on March 1, 2002 8:25:01 PM
quote: Original post by SabreMan
I'm not sure where you got this code from, but there are several mistakes. The canonical C++ form would look like:
...
<RANT TYPE = "IGNORANT" TONE = "MALICIOUS">
What's so canonical about that? It's called confusing to newbies . The STL wasn't in existence when C++ came out, but more importantly, the (now deprecated) iostream.h is just easier to deal with than forcing namespaces and templates on them all at once when they're first starting out. And if you're going to be that picky, why say that the return statement is implied? I'm fairly certain that the ANSI standard states that the return statement is required.
</RANT>
Later,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[if you have a link proposal, email me.]
EDIT: typos and stupid forum glitches
Edited by - zealouselixir on March 1, 2002 8:38:45 PM
Edited by - zealouselixir on March 1, 2002 8:39:50 PM
[twitter]warrenm[/twitter]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement