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.
Have Visual Studio with the Desktop development with C++ workload installed and running on your computer. If it's not installed yet, follow the steps in Install C++ support in Visual Studio.
Create a "Hello, World!" project and enter its source code. If you haven't done this yet, follow the steps in Create a C++ console app project.
If Visual Studio looks like this, you're ready to build and run your app:
Build and run your code in Visual Studio
To build your project, choose Build Solution from the Build menu. The Output window shows the results of the build process.
To run the code, on the menu bar, choose Debug, Start without debugging.
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.
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.
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.
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.
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.
In the command prompt window, right-click to paste the path to your app into the command prompt. Press Enter to run your app.
Congratulations, you've built and run a console app in Visual Studio!
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.
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.
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.