How do you run C++ programs on Ubuntu?

To run a C++ program on Ubuntu, you need to install a C++ compiler like GCC first. You can open the terminal and enter the following command to install GCC:

sudo apt-get update
sudo apt-get install g++

After installation is complete, you can use the following commands to compile and run C++ programs:

  1. The program you have written is named “your_program.cpp”.
#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}
  1. Compile the C++ program using the following command:
g++ your_program.cpp -o your_program
  1. Run the compiled executable file.
./your_program

In this way, you will be able to run C++ programs successfully on Ubuntu.

Leave a Reply 0

Your email address will not be published. Required fields are marked *