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

image

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

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

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 TechHowTos.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).

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

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 TechHowTos.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 TechHowTos.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 TechHowTos.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 TechHowTos.com

Learn more about interesting technology topics in our eBook: “Tech How To’s Vol. 1

Tech How To's Vol. 1 - Technology eBook by Artemakis Artemiou

 

Reference: TechHowTos.com (http://www.techhowtos.com)

© TechHowTos.com

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

Loading...

Recommended eBooks on SQL Server:

Tuning SQL Server: eBook by Former SQL Server MVP Artemakis Artemiou
Tuning SQL Server: eBook by Former SQL Server MVP Artemakis Artemiou
Administering SQL Server: eBook by Former SQL Server MVP Artemakis Artemiou
Administering SQL Server: eBook by Former SQL Server MVP Artemakis Artemiou

 

 

 

 

 

 

 

 

 

Share this!
About Artemakis Artemiou 30 Articles
Artemakis Artemiou is a Senior SQL Server and Software Architect, Author, and a former Microsoft Data Platform MVP (2009-2018). He has over 15 years of experience in the IT industry in various roles. Artemakis is the founder of SQLNetHub and TechHowTos.com. Artemakis is the creator of the well-known software tools Snippets Generator and DBA Security Advisor. Also, he is the author of many eBooks on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Artemakis's official website can be found at aartemiou.com.