C++ Hello World Sample Source Code

Hello World is basically the very first program which books and online tutorials teach to students beginning any programming language. Full Sample Code of the Hello World Project has been provided in this C++ Tutorial Post. All the C++ Projects on this website have been compiled using Microsoft Visual Studio Express Edition which is a Free Software from Microsoft.

In order to create a Hello World Project using Microsoft Visual Stdio Express Edition, Click on File and then select the option New project. Once you Start Creating the Project, a Dialog will open up and will prompt you the location, name and type of your new C++ Project. Select Any Location on your Hard Disk and specify the name as Hello World (Yes you can give any other name as well) and finally in the type of project to create, select Win 32 Console Application. This will allow you to create a simple C++ Program which can be run from the command prompt or from the Microsoft Visual Studio as well. Given below Screenshot displays the New Project Screen in Microsoft Visual Studio Express Edition for creating a Hello World Project using C++.

C++ Sample Hello World

C++ Sample Hello World

Once you have specified the C++ Project Name, Location and Type of the Project, Click on OK to Continue to the next step. In the next step you would need to specify about your C++ Project type and the screen is called Application Wizard as displayed below.

C++ Sample Hello World Win32 Application Wizard

C++ Sample Hello World Win 32 Application Wizard

In the Win 32 Application Wizard, Click on Finish to Continue and let’s get started to create your first C++ Project. You can even download the full source code from this post, but there are only two lines you need to type in this C++ Hello World Project. The Application Wizard will do the initial coding for you and all you would need to do is type in two lines and run your C++ Hello World Project. Given below screenshot displays the initial coding done by Application Wizard for you.

C++ Sample Hello World Initial Code

C++ Sample Hello World Initial Code

Yes you can even run this default code written by Application Wizard using the F5 Keyboard Shortcut. However it is a great idea to add simply two lines and let your first application (.exe) display some text on the console as given below.

C++ Sample Hello World Final Code

C++ Sample Hello World Final Code

Note that Green Lines displayed in the above screenshot are comments and are not compiled by the Visual Studio Compiler. Out of two lines written in this Hello World C++ Project, the line

#include <iostream>

is written to include the functionality to write to console. Your application is going to simply use the functionality offered by the iostream library and use the cout object to write Hello World to the Console using C++ as the programming Language.

std::cout << “Hello World”; actually writes to the console and whatever text you specify will get written to console when the application is run. In order to create an exe with the code you can press the keyboard shortcut F7 which basically launches the compiler and linker if there are no compilation errors. In case your C++ Code does not contain any compilation or linking errors, the linker will create an exe file in the Debug or Release Folder of your C++ project. You can alternatively press F5 to launch the Compiler, Linker and finally run the application in debug mode.You can alternatively press the Ctrl + F5 to launch the newly created exe as a┬áseparate┬áprocess outside of the Visual Studio.

C++ Sample Hello World Code Compilation Confirmation

C++ Sample Hello World Code Compilation Confirmation

The above screen is displayed by Visual Studio to confirm whether you want to build your project or run existing version. For this C++ Hello World project, click on Yes and check the check box which says Do not show this dialog again. This Build Confirmation Dialog will popup when you compile and build your C++ Source Code to .exe application file.

C++ Sample Hello World Running on Command Prompt Outside Visual Studio

C++ Sample Hello World Running on Command Prompt Outside Visual Studio

The above screenshot displays the folder location of the C++ Hello World Project in cmd.exe which is called the command prompt. The dir command lists the Hello World.exe application file and on running the Hello World.exe file the text displayed by the cout object is displayed on the command prompt. C++ is the most easiest language in the world and even though above all might seems like too much efforts, practice and interest in the C++ programming language can make it real fun to learn for everybody including beginners and professionals which do know other programming languages.