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:
- The program you have written is named “your_program.cpp”.
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
- Compile the C++ program using the following command:
g++ your_program.cpp -o your_program
- Run the compiled executable file.
./your_program
In this way, you will be able to run C++ programs successfully on Ubuntu.