Run c++ program in google colab

Harsh Prajapati
2 min readOct 18, 2021

--

Today, we discuss, how to compile and run c++ code in google colab and the Linux system. Google colab is useful for those users that want to run big programs or not have a capable system to run c++ programs. Another advantage of google colab is, user can share their file with others who can edit and run c++ programs as well.

Visit this link to show in better way : https://debuggingsolution.blogspot.com/2021/10/run-c-program-in-google-colab.html

Installation of c++ compiler

Refer to this link to download the compiler and also follow explained steps to install compile into your local machine Open Page .

Run and compile c++ program

1) To compile code : “g++ filename.cpp -o anyname “
2) To run program : “ ./anyname”
For example : We make one file like helloworld.cpp,

compile code : “g++ helloworld.cpp -o helloProgram”

,and run the program: “./helloProgram”

Run and compile C++(CPP) code in google colab

Follows steps to run c++ program into google colab :
Step 1 : write a “%%writefile nameOfFile.cpp” and run code
Step 2: To compile same program by writting “ ! g++ filename.cpp -o anyname”
Step 3: To run same program by writting a command “ ! ./anyname”

Download cpp file in google colab :

Use GPU in google colab : Runtime -> change runtime type

C++ program in Linux

Follow steps :

1. Install compiler

2. Create File — (vi filename.cpp)

3. Compile command — g++ filename.cpp -o anyname

4. Run code : ./anyname

Run c program

Download c++ compiler

Google colab

Run c++ program in c++

Compile and run program in c++

Run and compile c++ program in google colab.

Run cpp program

--

--

Harsh Prajapati

Enthusiastic to work on Natural Language Processing and Computer vision Domain.