Walkthrough: Create a standard C++ program
You can use Visual Studio to create standard C++ programs. By following the steps in this walkthrough, you can create a project, add a new file to the project, modify the file to add C++ code, and then compile and run the program by using Visual Studio.
You can type your own C++ program or use one of the sample programs. This walkthrough creates a console application that uses the set
container in the C++ Standard Library.
Note
If conformance with a specific version of the C++ language standard (for example, C++14, C++17, or C++20) is required, use the /std:c++14
, /std:c++17
, or /std:c++20
compiler option (Visual Studio 2017 or later.)
Prerequisites
To complete this walkthrough, you must understand the fundamentals of the C++ language.
Select a version
The following steps vary depending on which version of Visual Studio you're using. To see the documentation for your preferred version of Visual Studio, use the Version selector located at the top of the table of contents on this page.
Create a C++ project in Visual Studio
From the main menu, choose File > New > Project to open the Create a New Project dialog box.
At the top of the dialog, set Language to C++, set Platform to Windows, and set Project type to Console.
From the filtered list of project types, choose Console App then choose Next. On the next page, enter a name for the project, and specify the project location if desired.
Select the Create button to create the project.
Create a C++ project in Visual Studio 2017
Select New from the File menu, and then select Project.
In the Visual C++ project types pane, select Windows Desktop, and then choose Windows Console Application.
Type a name for the project. By default, the solution that contains the project has the same name as the project, but you can type a different name. You can also type a different location for the project.
Select OK to create the project.
Create a C++ project in Visual Studio 2015
Select New from the File menu, and then select Project.
In the Visual C++ project types pane, select Windows Desktop, and then choose Windows Console Application.
In the New Project dialog box, expand Installed > Templates > Visual C++, and then select Win32. In the center pane, select Win32 Console Application.
Type a name for the project. By default, the solution that contains the project has the same name as the project, but you can type a different name. You can also type a different location for the project.
Select OK to create the project.
Complete the Win32 Application Wizard.
Select Next, then make sure Console Application is selected and uncheck the Precompiled Headers box.
Select Finish.
Add a new source file
If Solution Explorer isn't displayed, on the View menu, select Solution Explorer.
Add a new source file to the project.
In Solution Explorer, right-click the Source Files folder, point to Add, and then select New Item.
In the Code node, select C++ File (.cpp), type a name for the file, and then select Add.
The
.cpp
file appears in the Source Files folder in Solution Explorer, and the file is opened in the Visual Studio editor.In the file in the editor, type a valid C++ program that uses the C++ Standard Library, or copy one of the sample programs and paste it in the file.
Save the file.
On the Build menu, select Build Solution.
The Output window displays information about the compilation progress, for example, the location of the build log and a message that indicates the build status.
On the Debug menu, select Start without Debugging.
If you used the sample program, a command window is displayed and shows whether certain integers are found in the set.