C++ Programming help.

Recommended Videos

Cranyx

New member
Mar 6, 2011
270
0
0
All I'm trying to do is run a simple "Hello World" program, but the output window closes immediately after the function starts running. I'm using Microsoft visual C++ 2008 if that helps, here's my code:

#include "stdafx.h"

#include
using namespace std;

int main ()
{
cout << "Hello World!";

return 0;
}

Please help.
 

Cranyx

New member
Mar 6, 2011
270
0
0
OK, now I've found that pressing "debug" (Which is supposed to run it) causes it to close, but hitting CTRL+F5 makes it work properly, could somebody please tell me why this is?

Somebody told me something about modern computers closing old style programs like that.
 

burningdragoon

Warrior without Weapons
Jul 27, 2009
1,934
0
0
I can't speak exactly why, but when you run the program in debug mode it will close after it's done. Probably because 'debugging' is for finding bugs, and if there are no bugs there's no need to keep it running. It's still works properly, it's just the simple program completes so quickly that you don't see anything.

ctrl+F5 is running it without debugging (aka just running). If you were to run the program from the command line it wouldn't close either.
 

Esotera

New member
May 5, 2011
3,396
0
0
http://cplusplus.com/forum/beginner/1988/#msg7682

There's an elegant solution to this problem. If you were developing in linux of course you wouldn't be having this problem :p

Also #include [iostream] should be #include , unless microsoft c++ is different from the standard.
Code:
And quote this post to get markup which makes your programs easier to read.