Walkthrough: Creating a Standard C++ Program (C++)
You can use Visual C++ in the Visual Studio integrated development environment (IDE) 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. The sample program in this walkthrough is a console application. This application uses the
set container in the C++ Standard Library.
Visual C++ follows the 2003 C++ Standard, with these major exceptions: two-stage name lookup, exception specifications, and export. Additionally, Visual C++ supports several C++0x features, for example, lambdas, auto, static_assert, rvalue references, and extern templates.
If compliance with the standard is required, use the
/Za compiler option to disable Microsoft extensions to the standard. For more information, see /Za, /Ze (Disable Language Extensions).
To complete this walkthrough, you must understand the fundamentals of the C++ language.
To create a project and add a source file
Create a project by pointing to New on the File menu, and then clicking Project.
In the Visual C++ project types pane, click Windows Desktop, and then click Windows Console Application.
For versions of Visual Studio older than 2017, 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.
Click OK to create the project.
For versions of Visual Studio older than 2017, complete the Win32 Application Wizard. Click Next, then make sure Console Application is selected and uncheck the Precompiled Headers box. Click Finish.
If Solution Explorer isn't displayed, on the View menu, click Solution Explorer.
Add a new source file to the project, as follows.
In Solution Explorer, right-click the Source Files folder, point to Add, and then click New Item.
In the Code node, click C++ File (.cpp), type a name for the file, and then click 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, click 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, click Start without Debugging.
If you used the sample program, a command window is displayed and shows whether certain integers are found in the set.
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.