Category: C++

Added: 17th of October 2020

Viewed: 727 times

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

This tutorial works in Ubunbu, Kubuntu, Xubuntu, Lubuntu, Ubuntu Mate and other Ubuntu based distributions. The tutorial also works in Linux Mint and other Debian based distributions.

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




Other Tips & Tutorials

C++

Guess the random number C++ code on Ubuntu and Ubuntu based distributions, Learning C++

Posted: 5th of October 2021

Views: 157

C++

Basic user input and output using C++ in Linux, Learning C++

Posted: 19th of December 2020

Views: 696

C++

Install Microsoft Visual Studio Code in Kubuntu, Ubuntu and Ubuntu based distributions. Compile and execute C++ script

Posted: 18th of October 2020

Views: 870

C++

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

Posted: 17th of October 2020

Views: 727