Support us


to write
more tutorials




to create new
visualizers




to keep sharing
free knowledge
for you


every dollar helps
Need help with a programming assignment? Get affordable programming homework help.

How to write Hello World! application in C++. From the installation of a development environment to your first code string.

This article is for the very beginners, making their first steps in programming. We will describe the whole process here, from the installation of a development environment to the writing of your first code string in C++. As the best suitable programming environment for the beginners, we have chosen Microsoft Visual C++ Express Edition. It is free and includes all you need to start: Code Editor, Compiler and Debugger.

Microsoft Visual C++ Express Edition Installation

  1. Go to the Microsoft Downloads Page and download Microsoft Visual C++ 2008 Express Edition.
  2. Run vcsetup.exe. It is an online installer.
  3. Click Next:
  4. Accept license agreement and click Next:
  1. You may skip these products for now, but they can be added in the future. Click Next:
  2. Remember, where you are installing Microsoft Visual Studio and click Install button:
  3. Wait, while setup download and install files:
  4. After setup is complete, press Exit:
  5. Close all active applications and click on Restart Now button:

Running Microsoft Visual Studio Express Editions

  1. Go to the Start - All Programs - Microsoft Visual C++ 2008 Express Edition and run Microsoft Visual C++ 2008 Express Edition. You should see the following:
  2. Go to the File - New - Project...:
  3. Choose Visual C++ - General - Empty project. Call your project "HelloWorldProject" and the solution would be "HelloWorldSolution":
  4. Click with right button on the Source Files folder of your project. Choose Add - New Item...:
  5. Choose Visual C++ - C++ file (.cpp) and call it "HelloWorldApp":
  6. Type a code from the image below into the Code Editor Window:
  7. Press the Run button:
  8. You should see a warning. Check "Do not show this dialog again" checkbox and click Yes:
  9. You should see a console window:

String by string analysis of your first program

#include <iostream>

 

This line includes iostream header, which allows us to use input/output functions.

int main()

{

It is an entry point for any console application. main() is a function, which runs first in the console application. int means that is should return an integer. Open curve bracket in C++ is reserved to indicate a beginning of a code block. In the current example it indicates beginning of a main function body.

      std::cout << "Hello world!" << std::endl; This line prints "Hello world!" to the console window and moves carriage to the new line.
      system("PAUSE"); This line of code prevents console windows from closing, until some key is pressed.
      return 0; This line tells the application to return control to the Operation System and quits the program. 0 means, that program finished normally.
} Close curve bracket in C++ is reserved to indicate the end of the code block. In the current example it indicates the end of the main function body.

Three responses to "How to write Hello World! application in C++ tutorial"

  1. Guest on Oct 8, 2009 said:

    Thanks mate, it was really helpful.

  2. Rones on July 5, 2009 said:

    I did exactly as told. But I get a build error.. it wont execute. This is what I get: ...

    We've started a topic on the forum: "Hello World! application in C++ tutorial" discussion. You are welcome to discuss it there.

  3. Colby on Feb 18, 2009 said:

    Everything has worked perfectly for me except that when i take it other places, it will not work. I get an error. It works fine on the computer i made it on though.

    It is a peculiarity of Visual Studio 2008. Applications made with it require installing additional libraries on a destination computer in order to run. We add the solution of this problem to the tutorial in the near future.

Contribute to AlgoList

Liked this tutorial? Please, consider making a donation. Contribute to help us keep sharing free knowledge and write new tutorials.


Every dollar helps!

Leave a reply

Your name (optional):
Your e-mail (optional):
Message: