C++: Using Visual Studio for C++

This entry is part 1 of 61 in the series C++

In an earlier post in Learn C, I have worked out a simple guide on compiling a C program using Visual Studio.

For compiling C++ using Visual Studio, we use very similar steps to compile and run a program.

If you have not downloaded C++, please download it from this link.

Launch the visual studio and click on New Project. The following screenshot will appear.


You can use the default name and click on OK.

In the Welcome To Win32 Application Wizard, click on Next.


Click On Empty Project as shown in the screenshot above.

An empty project with the following screen shot will be shown.


Notice the Solution Explorer on the right of the screen.

Now we want to create a file and put our source code there.

Right click on Source File in Solution Explorer.  Then Add -> New Item.

Name our first C++ program as Hello.cpp as shown in the screenshot below.


Click on Add.

Paste the code below to Hello.cpp.

#include <iostream>

int main()
	std::cout << "Hello World";

Click on Local Windows Debugger to run the program.


In our code, the cout is a standard string output in C++.  Notice the line getchar().  This is a C code and I have used it so that the console will prompt us to type in a character allowing us to see the Hello World text in the console.


Learn C: Using Visual Studio to compile a C program

This entry is part 7 of 7 in the series Learn C

The earlier posts were done using GNU C.

If you prefer, you could use the free version of Visual Studio Express from Microsoft.  This is a lot more easy to set up and unlike GNU C, you just have to download the Visual Studio Express and you are all set to write your first program.

Let’s walk through the process of writing your first C program.  You need to make a slight change to the source file name extension as the default setup for Visual Studio Express is in C++ with the cpp extension.

1.  The first step is to launch Visual Studio and from the file menu select New Project.



2.  As in the screenshot above, select Visual C++ and Win32 Console Application.

3.  Key in a new file name if you like.

4. The Win32 Application Wizard will be launched.


5. Click on next and the following page will be shown.


6. Select Console Application and click on Empty Project.

7. Deselect Precompile Header

8. Click on Finish

9.  An empty project similar to the screenshot below will be created.


10. Notice the Solution Explorer on the right of the screen.

11.  Right click on it and select Add -> New Item


12.  Change the file name to Hello.c as shown in the screenshot.

13.  The Hello.c file will be added to the Source File folder

14.  Paste the code below to the editor.

#include <stdio.h>

void main()
	printf("Hello World");

15.  Click on Local Windows Debugger


16.  This will compile and run the program.  The output will be as shown below: