How to run C++ code in Google Colab painlessly

Опубликовано: 18 Май 2026
на канале: Brian Byrne
15,524
137

see also:
how to include header and source files
   • Run C++ project in Google Colab combining ...  

https://sites.google.com/view/vinegar...

Create a notebook on Google Colab, and the create the necessary header source and main files. It is possible to execute C++ code right inside Google Colab. You can then expand Colab beyond just running Python scripts.

(C++ header file)
%%writefile test.h

(C++ source code):
%%writefile test.cpp

(C++ main)
%%writefile main.cpp
//Main function
int main(int Argc,char* Args[]){
return 0;
}

(Compile and run):
%%script bash

%%script bash

g++ main.cpp -std=c++11
./a.out