Zombie window / blank cmd / hello world

Sep 30, 2012 at 9:54pm
just wanted to start by saying hello and thanks for any help you guys can give me.

Okay im very new to the C++ world but i cant even start at the moment.

1
2
3
4
5
6
7
#include <iostream>
int main( void )
{
using std::cout;
cout << "Hello World!\n";
return 0;
}


i use this code and start it by using ctrl+f5

i get zero error's but then i get a blank cmd screen and the project name as .exe in my process list and i can't stop it and can't close the cmd window either.

Im running windows 7 64bit and using Microsoft Visual C++ 2008 Express Edition
Sep 30, 2012 at 9:59pm
For one, your using needs to be outside the main, under the #include
Sep 30, 2012 at 10:00pm
Try:
1
2
3
4
5
6
7
8
9
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}
Sep 30, 2012 at 10:09pm
i will try that just adding little info im using this book : C++ Programming for the absolut beginner. this is what they gave me :

Now, gentle reader, let us delve head first into the mystical world of C++. Though you may be
overwhelmed at first with the odd symbols and cryptic terms, it will all become clear in time.
So ready your torch and let us delve into this dark cavern!
1
2
3
4
5
6
7
8
//1.1 – Hello World – Mark Lee
#include <iostream>
int main( void )
{
using std::cout;
cout << "Hello World!\n";
return 0;
}

The above is a complete C++ program. It simply displays the words, “Hello World” to the
screen. Now, let’s take it apart, line-by-line!
Sep 30, 2012 at 10:13pm
okay just used your code same problem no errors but CMD window apears no text nothing and programm just dous nothing. cant stop it using shift+f5 or ctrl-C and also cant stop the process by trying to kill it.

It's a bit hard to explain maybe i should make a film and post it on youtube to show you guys what happens?

http://www.youtube.com/watch?v=9d_USzWFxPE

hope this helps
Last edited on Sep 30, 2012 at 10:40pm
Sep 30, 2012 at 10:49pm
Just wondering, are you actually making this in a Win32 console application and under a cpp file?

If you are then I'm not sure what the problem is but maybe try a different compiler
Sep 30, 2012 at 10:58pm
Just wondering, are you actually making this in a Win32 console application and under a cpp file? Yes i did. How do you change compiler ?
Sep 30, 2012 at 11:03pm
How do you change compiler ?

What program are you using to write and compile your code?
Last edited on Sep 30, 2012 at 11:03pm
Sep 30, 2012 at 11:12pm
Microsoft Visual C++ 2008 Express Edition so guesing this is also the compiler :P
Sep 30, 2012 at 11:18pm
I have Microsoft Visual Studio 2011 and it works on that. You can upgrade, or try Code::Blocks
Sep 30, 2012 at 11:37pm
okay this is strange i changed compiler and still getting the same problem check the youtube link to see whats happening.

http://www.youtube.com/watch?v=9d_USzWFxPE
Sep 30, 2012 at 11:50pm
I saw on your video that another instance of the cmd opened and then instantly closed.

Try adding
system("PAUSE");

to the bottom of your main function before the return just to see if your window is opening and instantly closing.
Sep 30, 2012 at 11:58pm
closed account (zb0S216C)
[-1 from TheJJJunk for suggesting the use of "system( )"]

apeachaday wrote:
"For one, your using needs to be outside the main, under the #include"

No, they do not. I fact, it's far better than "using namespace ...".

@mythrix: Try running your program from command-prompt. This is how you should be executing your programs, since console programs should not be held open.

Wazzak
Last edited on Sep 30, 2012 at 11:58pm
Topic archived. No new replies allowed.