COSC 112: Computer Science I


How to create a project and add a source file in Visual C++

To create a project and add a source file

  1. Create a project by pointing to New on the File menu, and then clicking Project.
  2. In the Visual C++ project types pane, click Win32, and then click Win32 Console Application.
  3. 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.

  1. In the Win32 Application Wizard, click Next, select Empty Project,and then click Finish.
  2. If Solution Explorer is not displayed, on the View menu, click Solution Explorer.
  3. Add a new source file to the project, as follows.
    1. In Solution Explorer, right-click the Source Files folder, point to Add, and then click New Item.
    2. 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.

  1. In the file in the editor, type a valid C++ program that uses the Standard C++ Library, or copy one of the sample programs and paste it in the file.

For example, you can use the set::find sample program, which is one of the the Standard Template Library samples that are included in Help.
If you use the 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).

  1. Save the file.
  2. 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.

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