Friday, 3 January 2020

How to Use Google Colab to Run C++ Code

Create a notebook on Colab, and create these 2 code blocks to run C++ code right inside Colab; it is interesting as Colab is not just for Python.

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

//Main function
int main(int Argc,char* Args[]){
  return 0;
}

Code block 2 (Compile and run):
%%script bash

g++ test.cpp -o test
ls -laX
./test

12 comments:

  1. Thank you so much! Such a simple solution, exactly what I was looking for

    ReplyDelete
  2. anyone explain how it work or how to use

    ReplyDelete
  3. However, I couldn't input data with cin :/

    ReplyDelete
    Replies
    1. You can substitute a file for input, such as creating a file called 'in.txt' and then reading it in with 'freopen'.

      Delete
    2. %%shell

      g++ archivo.cpp -std=c++14 -o test
      ./test

      -----------

      Yo uso %%shell en lugar de %% script bash

      Ya lo demas es opcional indicar la version de c++

      Delete
  4. Thanks for sharing the best information and suggestions, I love your content, and they are very nice and very useful to us. If you are looking for the best C++ Tutorial,then TutorialCup.I appreciate the work you have put into this.

    ReplyDelete
  5. (Note - Google has as of late redid the YouTube framework and gave numerous ways website admins can see the connecting information and details; incredible wellspring of data for website admins and advertisers.) https://www.sandeepmehta.co.in/affordable-seo-services-delhi/

    ReplyDelete
  6. The primary thing you should do is have a record at a recorder where you need your Google area to be moved to. https://onohosting.com/

    ReplyDelete