How to Write a “Hello World” App in Visual C++

In this tip, we are going to build a “Hello World” console application in Visual C++.

If you don’t already have Visual Studio, the you can download Visual Studio Community Edition which is free.

 

Building the App in Visual Studio

Ok, let’s build our Hello World app!

After launching Visual Studio, we click on “File“, “New“, “Project“.

How to Write a “Hello World” App in Visual C++ - Article on essentialDevTips.com

We then select the template for this new project, in this case “Visual C++” (1), the type of the project, in this case “Win32 Console Application” (2), the name and disk location of the project (3 and 4), and finally the solution name (5) which by default gets the same name as the project name but of course you can change it if you want. After all these are set, we click on the “OK” button (6).

Right after we click OK, we are presented with the ‘Win32 Application Wizard‘”. For this example, we just click on the “Finish” button.

How to Write a “Hello World” App in Visual C++ - Article on essentialDevTips.com

After clicking on the “Finish” button we are ready to write code. The below screenshot illustrates the development environment:

How to Write a “Hello World” App in Visual C++ - Article on essentialDevTips.com

As we want to perform an output operation, we need to add the <iostream> library to our application with the code line:

#include <iostream>

 

Also, we need to use the proper namespace (std) with the below code line:

using namespace std;

 

The last step is to add the code to be executed when our application runs:

The below command will display the “Hello World” message:

cout << "Hello World! This is a C++ program!";

 

And the getchar(); command will pause the console window in order to let us see the output.

After adding the above code lines we Build our application from the “Build” menu – “Build Solution” function.

How to Write a “Hello World” App in Visual C++ - Article on essentialDevTips.com

After our solution’s build operation succeeds, we can run our application by pressing F5 or by clicking on the debug button (play button sign). As we can see from the below screenshot, our program runs and successfully displays the “Hello World” message!

How to Write a “Hello World” App in Visual C++ - Article on essentialDevTips.com


Recommended course: “Introduction to Computer Programming for Beginners”

Enroll to our course on Udemy, titled  “Introduction to Computer Programming for Beginners” and get the help you need for getting started with C++, C, Python, SQL, Java, C# and the main phases of the Software Development Lifecycle.

Introduction to Computer Programming for Beginners - Enroll to the Course
(Lifetime access, downloadable resources, course completion certificate and more!)

Enroll to the Course


 

Recommended Online Courses:

 

Read Also:

 

Reference: {essentialDevTips.com} (http://www.essentialdevtips.com/)

© essentialDevTips.com

Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Loading...