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“.
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.
After clicking on the “Finish” button we are ready to write code. The below screenshot illustrates the development environment:
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.
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!
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.
Recommended Online Courses:
- SQL Server 2022: What’s New – New and Enhanced Features
- Introduction to Azure Database for MySQL
- Working with Python on Windows and SQL Server Databases
- Boost SQL Server Database Performance with In-Memory OLTP
- Introduction to Azure SQL Database for Beginners
- Essential SQL Server Administration Tips
- SQL Server Fundamentals – SQL Database for Beginners
- Essential SQL Server Development Tips for SQL Developers
- Introduction to Computer Programming for Beginners
- .NET Programming for Beginners – Windows Forms with C#
- SQL Server 2019: What’s New – New and Enhanced Features
- Entity Framework: Getting Started – Complete Beginners Guide
- A Guide on How to Start and Monetize a Successful Blog
- Data Management for Beginners – Main Principles
Read Also:
- Welcome to {essentialDevTips.com}!
- Understanding Dependency Injection in C#
- How to Write a “Hello World” App in C#
- How to Rebuild All Indexes Online for a SQL Server Database
- Benefits of Primary Keys in Database Tables
- Main Data Structures in Python
- How to Fix: Slow WiFi Internet Connection on Windows 10 Laptop
- SyntaxError: invalid syntax when using IF in Python – How to Resolve it
- Using Dynamic Memory Allocation in Java
Reference: {essentialDevTips.com} (http://www.essentialdevtips.com/)
© essentialDevTips.com
Rate this article:
Artemakis Artemiou is a Senior SQL Server Architect, Author, a 9 Times 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 {essentialDevTips.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). Moreover, Artemakis teaches on Udemy, you can check his courses here.