Hello, please help me. I am using microsoft visual C++ 2008 express edition.

I am following Sams teach yourself C++ in ten minutes and am stuck on "hello world"

This is my source code file:

#include <iostream.h>

int main()
{
    cout << "Hello World!\n";
    return 0;
}

I clicked "Build solution" and then when I try to "start without debugging" all I get is a black window appear saying "press any key to continue...". No "Hello World!" is displayed.

I am confused because I am following the instructions precisely or so I think.

Any input gladly appreciated.

Thank you

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Hello, thanks for responding.

Code now reads:

#include <iostream>

int main()
{
    std::cout << "Hello World!\n";
    return 0;
}

And I still have the same problem. ??

Edited 3 Years Ago by mike_2000_17: Fixed formatting

You've got your code written in "hello.cpp" but it's not part of the project you have open, chances are it's building "program.cpp" & hence the output you're getting.

Put that code into "program.cpp" then try rebuilding & running it.

first off iostream.h is not standard so dont bother using it. use
#include<iostream> instead.

to solve your problem try doing this :

#include<iostream>

using namespace std; //important.

int main(){

cout<<"Hello world."<<endl;

return 0;
}
Comments
What he said. And what you posted was wrong anyway, you don't need "using namespace std;"
Way to not read the thread before replying and way to not use code tags.

firstPerson, more important is Code Tags.

To use command prompt, go to Start->Programs->Accessories, then use cd to navigate to the file and then type the name of the program.

Hello just to let people know, I tried running the compiler as administrator as I have Vista and it is now working. Thanks for the advice.

>Maybe these screenshots will show what I am doing wrong?
Yes. Like Yiuca said, source files have to be added to the project in order for them to get built. Just because you're editing the file in Visual Studio doesn't mean it's added to your project; check the left sidebar, which should show all the files in the project.

Replace the contents of program.cpp with your hello world code, recompile everything, and it should work fine.

This article has been dead for over six months. Start a new discussion instead.