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

Recommended Answers

All 13 Replies

that book is a tad outdated
replace <iostream.h> with this:

#include <iostream>
using std::cout;

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. ??

Seems wird it should work fine. Try clicking re-build

Chris

Have you tried running it from the command prompt?

How do I run from the command prompt John? Thanks.

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;
}
commented: Way to not read the thread before replying and way to not use code tags. -1
commented: What he said. And what you posted was wrong anyway, you don't need "using namespace std;" -1

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.

Nothing works :(

And I don't understand you mosaic.

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.

*Scratches His Head*
Frickin' Permissions.

>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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.