About this C++ playground
This is a C++ compiler you can use straight away. Write C++ in the editor, press Run, and your program is compiled with g++ and run. The output appears next to it: everything it prints, any compiler error or warning with its line number, the exit code, and how long it took.
It compiles as C++20, so ranges, concepts, structured bindings and the rest of modern C++ are there, in an isolated sandbox on our servers. It is free, with nothing to install and no account needed.
What you can run
- GCC 11.4, C++20, running one file per run, saved as
main.cpp. - Compiled, then run. Each run compiles your file with
g++ -std=c++20 -O2 -Wall -o main main.cppand runs the program if it compiles. Compiler errors and warnings appear in the output like any other error. - Standard library only. The whole C++ standard library is there: iostream, string, vector, map, unordered_map, algorithm, ranges, memory, regex, chrono and the rest, plus the C headers. There is no package installer, and programs have no network access.
- Limits: 10 seconds and 256 MB of memory per run, plus up to 20 seconds to compile first. Output past 64 KB is cut off, code can be up to 64 KB and input up to 16 KB.
- Fair use: 5 runs a minute and 50 a day without an account, 10 a minute when you are signed in.
Reading input
Open the Input box under the editor and type what your program should read. std::cin reads it as standard input: cin >> reads the next word or number, and getline the next line. With the box empty, the read fails and cin tests false.
int age; if (std::cin >> age) std::cout << age << '\n';
Frequently asked questions
Is this online C++ compiler free?
Yes. There is no sign-up and no limit on how much you can write. Signed-out visitors get a quick, usually invisible bot check when they press Run, and a fair-use cap of 5 runs a minute and 50 a day. Signing in raises it to 10 runs a minute.
Which compiler and C++ version does it use?
GCC 11.4 (g++) on Ubuntu Linux, compiling as C++20 with g++ -std=c++20 -O2 -Wall. Nearly all of C++20 works, including ranges, concepts and designated initialisers. std::format is the main gap: it arrived in GCC 13, so use iostream or printf instead.
Why does compiling take a few seconds?
The standard headers are large, so g++ takes about two seconds for a program that includes iostream, and longer with heavy headers such as regex. Compiling has 20 seconds of its own, separate from your program's time, so a slow compile never cuts your program short.
Can I use bits/stdc++.h?
Yes, it is GCC's own header and it works here, but it includes the entire standard library, so compiling takes noticeably longer. Including only the headers you use is quicker.
Why did my program stop with a time-out?
Compiling gets up to 20 seconds of its own. Then the program gets 10 seconds and 256 MB of memory, and is stopped if it goes past either. The usual cause is a loop that never ends, or a cin read in a loop waiting for input that is not in the Input box.
Is my code saved or shared?
Your code is kept in your own browser so it is still there next time, and nowhere else. When you press Run it is sent to our code runner, run once in a sandbox, and thrown away. We do not store it or show it to anyone.