How to Compile and Run a CPP File in CMD
A file with the file extension of CPP is a C++ source code file. If you have the Microsoft Visual Studio (or similar) development environment installed, you can compile a CPP file from the Visual Studio command (CMD) prompt. Compile a CPP source code file to create an executable (EXE) file that may be run in DOS and/or Windows. Once the CPP file is compiled, you can also run the resulting executable file from the CMD prompt.
Things You'll Need
- Microsoft Visual Studio (or similar) integrated development environment installed
Instructions
-
-
1
Click the Windows "Start" button, and then click "All Programs."
-
2
Click the "Microsoft Visual Studio 2010" option, and then click on the link for the "Visual Studio Tools."
-
-
3
Click the "Visual Studio 2010 Command Prompt" option to open the Visual Studio command prompt.
-
4
Type "cl filename.cpp" (without quotes) and press the "Enter" key to compile the "filename.CPP" source code file into an executable (EXE) file with the name "filename.exe." Change the name "filename" in this example to the filename of your CPP file.
-
5
Type "start filename.exe" to run the executable file from the CMD prompt. Alternatively, double-click on the "filename.exe" file to run the program in Windows (where "filename" is the name of your CPP file).
-
1