Home | About | Categories | All Tips & Tutorials

Create a simple c++ script using Ubuntu and other Ubuntu based distributions, Learning C++

ID: 197

Category: C++

Added: 17th of October 2020

Views: 2,212

To create a simple C++ script in Ubuntu and other Ubuntu based distributions do the following

C++ should already be installed in your distribution, to check open your terminal and enter the following command

which cpp

If installed it will show you the path to cpp
/usr/bin/cpp

If C++ is not installed in your distribution, there will be no output from the terminal.
In this case we need to install C++, so please enter the following in your terminal
sudo apt-get install cpp

Once installed, we can now write and compile our first C++ script that will be executed through the terminal.

Create a new file on your desktop named myfirstscript.cpp
If not obvious the .cpp extension refers to c++

Open the file you just created in your distributions text editor, then copy and paste the code below.
#include <iostream>
int main ()
{
std::cout << "Hello, Welcome To My Computer Tips" <<std::endl;
return 0;
}

Next we need to compile and create an executable file.
Open your terminal and enter the following command
g++ myfirstscript.cpp -o myfirstscript

Next we need to run the script
./myfirstscript