Site icon TestingDocs.com

Compile & Execute C++ Program

Overview

In this tutorial, we will learn to compile and execute a C++ program using the Windows command line prompt.

Install GNU GCC C++ Compiler

Steps to install GNU GCC C++ compiler:

https://www.testingdocs.com/install-gnu-c-c-compiler-on-windows/

Write C++ code

General steps to execute the program are as follows:

 

 

/************************************
* Hello World C++ Program
* Filename: main.cpp
* C++ Tutorials - www.TestingDocs.com
*************************************/

// C++ Header file
#include 
using namespace std;
// Entry Point : main routine.
int main()
{
    cout << "Hello, World!"; // print message
    return 0;
}

Compile C++ Program

Open the Command prompt and issue the following command to compile the code.

\> g++ main.cpp

If there are no errors in the code a.exe executable file would generate.

Execute C++ Program

Now, type ‘a.exe’ to run the C++ program. You would be able to see ‘ Hello, World !’ printed on the console.

That’s it. We have successfully compiled and executed a C++ program using the Windows command prompt.

C++ Tutorials

C++ Tutorials on this website:

https://www.testingdocs.com/c-coding-tutorials/

For more information on the current ISO C++ standard

https://isocpp.org/std/the-standard

Exit mobile version