Creating a Standard C++ Program (C+)

With Visual C++ 2008, you can create Standard C++ programs by using the Visual Studio development environment. By following the steps in this topic, 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 that is used in this topic is a console application. The application uses the set container in the Standard Template Library (STL), which is part of the ISO C++ 98 standard.

Visual C++ complies with these standards:

  • ISO C 95

  • ISO C++ 98

  • Ecma C++/CLI 05


    To enforce ANSI C++ and ANSI C compliance checking of your program, use the /Za compiler option. (The default option is /Ze, which allows 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

  1. On the File menu, point to New, and then click Project.

  2. Under Project types, expand Visual C++, and then select Win32. Under Templates, click Win32 Console Application.

  3. Type a project name.

    By default, the solution that contains the project has the same name as the new project, but you can type a different name. You can also type a different location for the project.

    Click OK to create the project.

  4. In the Win32 Application Wizard, click Application Settings to reveal options for Application type. Under Additional Options, select Empty Project and then click Finish.

To add a new source file to the project

  1. In Solution Explorer, right-click the Source Files folder, point to Add, and then click New Item.

  2. On the Visual Studio installed templates list, select C++ File (.cpp), type a file name, and then click Add.

    The .cpp file appears in the Source Files folder in Solution Explorer and is automatically opened in the code editor.

  3. Copy the sample program from set::find (STL Samples) by clicking the Copy Code link under Example, and then paste the code into the empty file in the editor.

    You can also choose a different sample program, or type your own valid C++ program into the empty file.

    If you use the suggested sample program, notice the using namespace std; directive. This directive enables the program to use cout and endl without requiring fully qualified names (std::cout and std::endl).

To build and examine the program

  1. 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 states the build status.

  2. 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.

Next Steps

Previous:Creating Command-Line Applications (C+) | Next:Compiling a Native C++ Program from the Command Line (C+)

See Also


Visual C++ Guided Tour

Other Resources

C++ Language Reference

Standard C++ Library Reference

Change History




July 2009

Revised example code build process.

Customer feedback.