Export (0) Print
Expand All
111 out of 183 rated this helpful - Rate this topic

How to: Create a Standard C++ Program 

With Visual C++ 2005, you can create Standard C++ programs using the Visual Studio Development Environment. In this procedure, you create a new project, add a new file to the project, edit the file to add C++ code, and then compile and run the program using Visual Studio.

You can type in your own C++ program or use one of the sample programs. The sample program referred to in this procedure is a console application that uses the set container in the Standard Template Library (STL), which is part of the ISO C++ 98 standard.

Visual C++ conforms to these standards:

  • ISO C 95

  • ISO C++ 98

  • Ecma C++/CLI 05

    NoteNote

    You should use the /Za compiler option if you want to enforce ANSI C++ and ANSI C compliance checking of your program (the default option is /Ze which allows Microsoft extensions to the standard). See /Za, /Ze (Disable Language Extensions) for more information.

To create a new project and add a source file

  1. Create a new project:

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

  2. From the Visual C++ project types, click Win32, then click Win32 Console Application.

  3. Enter a project name.

    By default, the solution that contains the project has the same name as the new project, though you can enter a different name. You can enter a different location for the project if you wish.

    Click OK to create the new project.

  4. In the Win32 Application Wizard, select Empty Project and click Finish.

  5. If Solution Explorer is not visible, click Solution Explorer on the View menu.

  6. Add a new source file to the project:

    • Right-click on the Source Files folder in Solution Explorer and point to Add and click New Item.

    • Click C++ File (.cpp) from the Code node, enter a file name, and then click Add.

    The .cpp file appears in the Source Files folder in Solution Explorer and a tabbed window appears where you type in the code.

  7. Click in the newly created tab in Visual Studio and type in a valid C++ program that uses the Standard C++ Library, or copy and paste one of the sample programs.

    For example, you can use the set::find (STL Samples) sample program in the Standard Template Library Samples topics in the help. See How to: Compile a Code Example from the Help Topics for information on copying a sample program to the Clipboard.

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

  8. On the Build menu, click Build Solution.

    The Output window displays information about the compilation progress, such as the location of the build log and a message indicating that the build succeeded.

  9. On the Debug menu, click Start without Debugging.

    If you used the sample program, a command window is displayed that shows whether certain integers are found in the set.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.