The first thing you must do is create a new C++ project. Visual Studio Community provides a wizard to help you do that. Start Visual Studio Community and from the window that opens (Figure 1), click on the “Create a new project” button.

Figure 1 Starting a new project from Visual Studio’s main menu

Alternatively, if you click on the “Continue without code” link, then, from Visual Studio’s main menu you can select “File → New → Project” as shown in Figure 2.

Figure 2 Starting a new project from Visual Studio’s main menu

The “Create a new project” dialog box appears. In the right pane, select “Console App” as shown in Figure 3, and click on the “Next” button.

Figure 3 Selecting the C++ Console App

In the “Configure your new project” window that opens (see Figure 4), in the “Project name” field, you need to enter the name of your project. Type “testingProject” and click on the “Create” button.

Figure 4 Configuring your new project

The project is created and opened in your Visual Studio environment. You should see the following components (Figure 5):

  • the “Source Editor” window with the file called “testingProject.cpp” open. In this file you can write your C++ code. Of course, one single project can contain many such files
  • the “Solution Explorer” window, which contains a tree view of the components of the projects, including source files, libraries that your code may depend on, and so on
Figure 5 Viewing the “Source Editor” and “Solution Explorer” windows in Visual Studio

Notice: In case your code includes any of the Boost C++ Libraries, you should include those libraries in your project. To do this, from the main menu, select “Project → testingProject Properties”. In the popup window that appears, click on the dropdown arrow to expand the “Configuration Properties → C/C++ → General”. This will open the “General” properties for C++. In the “Additional Include Directories” field, type “C:\boost”, as shown in Figure 6

Figure 6 The project’s properties window

Notice: The Boost C++ Libraries must be present on your system. If you haven’t installed them yet, follow the steps described here.

You have just seen how to create a new C++ console project. Let’s now write the following (terrifying, and quite horrifying!) C++ program and try to execute it.

#include <iostream>
using namespace std;
int main() {
  cout << "Hello, World!" << endl;
  cout << "Hallo, Welt!" << endl;
  cout << "Bonjour, le Monde!" << endl;
}

Delete everything written in the “Source Editor” (“testingProject.cpp”)

Type only the first character, “#”, from the #include <iostream> statement by hitting the “#” key on your keyboard. A popup window appears, as shown in Figure 7. This window contains all available C++ statements, and other items that begin with the character “#”.

Figure 7 The popup screen in the Source Editor window

You can highlight a selection by using the up and down arrow keys on your keyboard.

Type the second character, “i”, from the #include <iostream> statement. Now the options have become fewer. Select the option “#include” using the down arrow key from your keyboard  (if necessary), as shown in Figure 8.

Figure 8 The popup screen in the Source Editor window

Hit the “Enter ⤶” key. The keyword is automatically entered into your program. Complete the statement by writing #include <iostream>. Then, continue typing the rest of the C++ program (as shown in Figure 9). Save the changes that you have just made. Your Visual Studio Code environment should look like this.

Figure 9 Entering a C++ program in the “testingProject.cpp” file

And now, let’s try to execute it! From the main menu, select “Debug → Start Without Debugging”.

The C++ program executes, and the output is displayed in the “Debug Console” window, as shown in Figure 10.

Figure 10 Viewing the results of the executed program in the “Debug Console” window

Notice: Alternatively, you can execute a file by hitting the CTRL + F5 key combination.

Congratulations! You have just written and executed your first C++ program!

Notice: You should always save your changes before executing a program. To do so, from Visual Studio’s main menu you can select “File → Save” or hit the “CTRL + S” key combination!

Now let’s write another C++ program, one that prompts the user to enter their name. Type the following C++ program into Visual Studio and hit CTRL + F5 to execute the file.

#include <iostream>
using namespace std;
int main() {
	string name;

	cout << "Enter your name: ";
	cin >> name;
	cout << "Hello " << name << endl;
}

Once you execute the program, the message “Enter your name:” is displayed in the “Debug Console” window. The program waits for you to enter your name, as shown in Figure 11.

Figure 11 Viewing a prompt in the “Debug Console” window

Type your name and hit the “Enter ⤶” key. Once you do that, your computer continues executing the rest of the statements. When execution finishes, the final output is as shown in Figure 12.

Figure 12 Responding to the prompt in the “Debug Console” window

Press any key to close the window.