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
- Go to the Microsoft Downloads Page and download Microsoft Visual C++ 2008 Express Edition.
- Run vcsetup.exe. It is an online installer.
- Click Next:
- Accept license agreement and click Next:
- You may skip these products for now, but they can be added in the future. Click Next:
- Remember, where you are installing Microsoft Visual Studio and click Install button:
- Wait, while setup download and install files:
- After setup is complete, press Exit:
- Close all active applications and click on Restart Now button:
Running Microsoft Visual Studio Express Editions
- 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:
- Go to the File - New - Project...:
- Choose Visual C++ - General - Empty project. Call your project "HelloWorldProject" and the solution would be "HelloWorldSolution":
- Click with right button on the Source Files folder of your project. Choose Add - New Item...:
- Choose Visual C++ - C++ file (.cpp) and call it "HelloWorldApp":
- Type a code from the image below into the Code Editor Window:
- Press the Run button:
- You should see a warning. Check "Do not show this dialog again" checkbox and click Yes:
- 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"
- on Oct 8, 2009 said:
Thanks mate, it was really helpful.
- 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.
- 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!