{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"markdown","source":"# Running C++ in Notebooks\n\nHat tip to this discussion: https://www.kaggle.com/c/abstraction-and-reasoning-challenge/discussion/131230\n\nSince the Kaggle image has a the `gcc` compiler and `g++`, it is actually possible to run C++ code in Kaggle Notebooks.\n\nLet's see what version of `gcc` we have:"},{"metadata":{"trusted":true},"cell_type":"code","source":"!g++ -v","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"I've written a short test script that writes to a file called `submission.csv`. Let's take a look:"},{"metadata":{"trusted":true},"cell_type":"code","source":"! head -n 20 /kaggle/input/c-execution-example/test_c_code.cpp","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"This file can be uploaded in a dataset or written within the notebook!\n\nOk, let's run the code"},{"metadata":{"trusted":true},"cell_type":"code","source":"import os\nimport pandas as pd\n\nos.system(\"g++ /kaggle/input/c-execution-example/test_c_code.cpp && ./a.out\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Here's the submission file:"},{"metadata":{"trusted":true},"cell_type":"code","source":"submission = pd.read_csv(\"submission.csv\")\nsubmission","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}