Build and run a C++ console app project

When you've created a C++ console app project and entered your code, you can build and run it within Visual Studio, and then run it as a stand-alone app from the command line.

Prerequisites

If Visual Studio looks like this, you're ready to build and run your app:

Ready to build the new project

Build and run your code in Visual Studio

  1. To build your project, choose Build Solution from the Build menu. The Output window shows the results of the build process.

    Build the project

  2. To run the code, on the menu bar, choose Debug, Start without debugging.

    Start the project

    A console window opens and then runs your app. When you start a console app in Visual Studio, it runs your code, then prints "Press any key to continue . . ." to give you a chance to see the output.

Congratulations! You've created your first "Hello, world!" console app in Visual Studio! Press a key to dismiss the console window and return to Visual Studio.

I ran into a problem.

Run your code in a command window

Normally, you run console apps at the command prompt, not in Visual Studio. Once your app is built by Visual Studio, you can run it from any command window. Here's how to find and run your new app in a command prompt window.

  1. In Solution Explorer, select the HelloWorld solution and right-click to open the context menu. Choose Open Folder in File Explorer to open a File Explorer window in the HelloWorld solution folder.

  2. In the File Explorer window, open the Debug folder. This contains your app, HelloWorld.exe, and a couple of other debugging files. Select HelloWorld.exe, hold down the Shift key and right-click to open the context menu. Choose Copy as path to copy the path to your app to the clipboard.

  3. To open a command prompt window, press Windows-R to open the Run dialog. Enter cmd.exe in the Open textbox, then choose OK to run a command prompt window.

  4. In the command prompt window, right-click to paste the path to your app into the command prompt. Press Enter to run your app.

    Run the app at the command prompt

Congratulations, you've built and run a console app in Visual Studio!

I ran into a problem.

Next Steps

Once you've built and run this simple app, you're ready for more complex projects. See Using the Visual Studio IDE for C++ Desktop Development for more detailed walkthroughs that explore the capabilities of Visual C++ in Visual Studio.

Troubleshooting guide

Come here for solutions to common issues when you create your first C++ project.

Build and run your code in Visual Studio issues

If red squiggles appear under anything in the source code editor, the build may have errors or warnings. Check that your code matches the example in spelling, punctuation, and case.

Go back.

Run your code in a command window issues

You can also navigate to the solution Debug folder at the command line to run your app. You can't run your app from other directories without specifying the path to the app. However, you can copy your app to another directory and run it from there.

Go back.