Having trouble with the "Hello World" program.

Everytime I try to "Hello World", I always get an error stating that the program is illeagel. Considering syntax errors. Now I'm getting one saying I need a 32-bit computer. This is how I've been writing the "Hello World":

#include <iostream>

using namespace std;

void main (void)

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

return 0;

system (PAUSE);
Last edited on
#include <iostream>

using namespace std;

/*void*/ int main() // main *must* return int
    cout << "Hello world." << endl;
    return 0 ; // exit from main

    // nothing that you write here will execute; main() has already returned 

Put everything in main() between the { and }
Thanks. But now I'm getting a message saying that my program is not compatible with the type of Windows I'm running. I am on a 64-Bit laptop so is there any way that I can change the program? (I'm using Notepad, would I need to use VC++E?)
Last edited on
You can continue to use Notepad to write your program, but you do need a current compiler.

VC++E would be a reasonable option.
What compiler are you using? Notepad is just a text editor. If you're using a compiler such as g++, you simply run a command like this:
g++ C:/path/to/file/main.cpp

That should compile it for you. Then you simply run the code as follows:

These are very basic commands and can result in issues when you do more programming, but to get the simple hello world compiled, it should suffice. Make sure you change main to whatever the name of your C++ file name is.
Last edited on
I can recomend u to use Code Blocks. Very useful and still simple. And its free =)

Easy to set up, and the built in functions is very helpful when learning C++
I am starting to believe that "Hello, World" is the most difficult C++ program!:)
I don't use Code::Blocks because ti confuses me. I used VC++E for the program, but it said that the program did not exist after I debugged and ran it. I guess I'll just look it up on youtube how to use VC++E. Maybe that could help.
I don't use Code::Blocks because ti confuses me.

I've never heard that statement when compared to MSVCE. Typically, beginners are more confused by MSVCE than C::B because there is so much going on in MSVCE. If you download the 10.05 version from codeblocks.com, it comes already set up for you. You can even select a console application from the new project list that already has a simple hello world program written for you (as a test to make sure everything installed correctly).

You also don't need system pauses (which if you read about the system function, you understand why this is a good thing). Aside from that, C::B is a much lighterweight IDE than MSVCE IMHO. This comes in handy for beginners because there isn't too much on the screen at once to overwhelm you. You have an editor window, a few toolbars (to make it easy to access commonly used commands), and a log window to see what's going on.

I'd honestly try to stick with a basic text editor (like notepad or something better) and just download a separate compiler. This will allow you to completely customize your programs the way you want them without having to fight with the IDE.
Well it always tells me about having to download a compiler. I've downloaded a bunch and none of them work.
I suggest using the g++ compiler. You can find the GCC compiler collection for Windows (which is distributed by MinGW) here:

Once you run it, it asks you several questions. Make sure you select atleast g++ (I'd also suggest selecting gcc as well). This takes several minutes depending on your internet connection. Once it finishes, it will have installed everything you told it to download. You can then use the compiler 1 of 3 ways.

1) You can add the path of the compiler to the System PATH (some people frown upon this) but this can be a little tricky. Make sure you don't erase anything in there, if you have doubts about doing it, click cancel and nothing is saved.

2) You can manually call the compiler from the command line as so (assuming you used the default install location):
C:\MinGW\bin\g++ C:\path\to\file\main.cpp

Then run it as so:

You have a very wide range of options when it comes to compilers/environments, but I suggest using the g++ compiler since I'm not even 100% what the commands for MSCVE compiler are.
Try this:

a. Download ftp://ftp.equation.com/gcc/gcc-4.8-20120819-32.exe

b. Run the exe to install the tool chain
(choose any directory that you please as the install directory)

c. Log out of of windows and log in again

d. cd to the directory containing your program (say hello_world.cpp)

e. build it with: > g++ --std=c++11 -pedantic -Wall -o hello_world.exe hello_world.cpp
(compile my hello_world.cpp and create the executable hello_world.exe )

f. run it with: > hello_world

EDIT: Duplicate post. Letting it remain because it is a different version and build.
Last edited on
Don't worry :) I finally got it to work! :D

Topic archived. No new replies allowed.