Last updated:2026-10-12
Interactive C++ in Jupyter Notebook¶
In Python, we can use Jupyter Notebook to see results directly, for example:
It directly outputs:
But when using C++, for example:
To print it you would have to loop over it — couldn't we just print the result directly?
So easy!!! Jupyter Notebook can solve everything, haha~
How to Play with C++ in Jupyter?¶
There is a repository on GitHub, shown below:
xeus-cling is a Jupyter kernel for C++, based on a native implementation of the C++ interpreter and the Jupyter protocol xeus.
Currently, it supports macOS and Linux, but not Windows.
Installation is also very simple: first install Anaconda, then create a virtual environment inside it:
Switch into it:
Install jupyter and notebook for the new environment:
Install xeus-cling using conda-forge:
To speed up installation, remember to configure a package mirror for Anaconda!
Check whether the kernel is installed:
Output:
python3 /home/xxx/anaconda3/envs/cling/share/jupyter/kernels/python3
xcpp11 /home/xxx/anaconda3/envs/cling/share/jupyter/kernels/xcpp11
xcpp14 /home/xxx/anaconda3/envs/cling/share/jupyter/kernels/xcpp14
xcpp17 /home/xxx/anaconda3/envs/cling/share/jupyter/kernels/xcpp17
Open Jupyter Notebook and you will see the kernel.
Start Jupyter Notebook:
How to Play with C in Jupyter?¶
You only need to install a C kernel!
You can create the C kernel directly in the current environment, or set up a new environment for it; below we install it directly in the current environment.
Now it outputs:
c /home/light/anaconda3/envs/cling/share/jupyter/kernels/c
python3 /home/light/anaconda3/envs/cling/share/jupyter/kernels/python3
xcpp11 /home/light/anaconda3/envs/cling/share/jupyter/kernels/xcpp11
xcpp14 /home/light/anaconda3/envs/cling/share/jupyter/kernels/xcpp14
xcpp17 /home/light/anaconda3/envs/cling/share/jupyter/kernels/xcpp17
Start Jupyter Notebook:
Related Topics¶
- Building C++ Projects with Bazel | C++那些事
- Debugging Bazel Builds with LLDB | C++那些事
- CMake Essentials in Practice | C++那些事
- Getting Started with the Conan C++ Package Manager | C++那些事
- C++ Insights Compile-Time Observation | C++那些事
- C++ string to int | C++那些事
- The C++ dbg-macro Debugging Macro | C++那些事
- GCC Compilation Flags Explained | C++那些事
- Debugging C++ Programs with GDB | C++那些事
- GDB Python Extension Debugging | C++那些事