how to run c++ program in cmd code example
Example 1: run cmd command c++
#include <iostream>
using namespace std;
int main() {
system("DATE");
return 0;
}
Example 2: c++ compile to exe command line
gcc sourcefile_name.c -o outputfile.exe
Example 3: run c++ in command prompt windows
1. Download, install the compilerand and edit Environment Variables.
2. Type the C/C++ program and save it.
3. Open the command line and change directory to the particular one where
the source file is stored
4. To compile, type in the command prompt:
gcc sourcefile_name.c -o outputfile.exe
Ex: gcc HelloWorld.c -o HelloWorld.exe
5. To run the code, type:
outputfile.exe
Ex: HelloWorld.exe