Online C++ Compiler

Compile and run C++20 code online with Clang running in your browser: STL containers, algorithms, iostream and stdin input. No sign-up, nothing is uploaded.

C++20 (Clang 21, WebAssembly) · Runs in your browser, so your code never reaches our servers.
main.cppC++
Output

            
Input (stdin), read by scanf / std::cin / getline
Ctrl/⌘ + Enter to run

How to use the online C++ compiler

  1. Type or paste your C++ code into the editor. It needs an int main(). Reset example brings back the starter program.
  2. If your program reads from std::cin or std::getline, put the input in the Input (stdin) box first.
  3. Press Run, or Ctrl + Enter (⌘ + Enter on a Mac). The page compiles main.cpp, shows any diagnostics, and then runs the program.
  4. Pick a time limit of 5, 15 or 60 seconds. When a run exceeds it, the program is stopped. Stop ends it at once.

On the first run the page downloads the Clang toolchain, roughly 30 MB, which your browser then caches. After that, compiling a typical program takes well under a second. Copy and main.cpp let you keep your code, A−/A+ resize the text, the layout button switches between side-by-side and stacked panes, and Full screen (Ctrl/⌘ + Shift + F, Esc to exit) gives the editor the whole window.

Nothing is uploaded. The compiler and your program both run in your browser, and your latest code is saved only in your browser's local storage.

What's supported

The page uses a genuine Clang/LLVM 21 compiler, built for WebAssembly by the YoWASP project. It compiles your source into a WebAssembly (WASI) program that the browser executes. The command it runs is equivalent to:

clang++ main.cpp -std=c++20 -O2 -Wall -fno-exceptions -o main.wasm
  • C++20: auto, lambdas, range-based for, structured bindings, constexpr, concepts and designated initialisers.
  • The standard library from libc++: vector, string, map, unordered_map, set, algorithm, numeric, iostream, sstream, iomanip, optional and the rest of the containers and algorithms.
  • Clang's own diagnostics, printed exactly as the compiler reports them with main.cpp:line:column, including template errors and -Wall warnings.
  • A non-zero return from main is reported as Process exited with code N.

Why exceptions are turned off

C++ exceptions need extra runtime support in WebAssembly that this in-browser toolchain does not provide, so the code is compiled with -fno-exceptions. As a result, try, throw and catch are not supported, and code that uses them fails to compile. Library functions that would normally throw, such as std::stoi on bad input or .at() with an index out of range, cannot be caught here either. Check the input before converting it, test indexes against size(), or return a std::optional to signal failure:

#include <optional>
#include <string>

std::optional<int> parse(const std::string& s) {
    if (s.empty()) return std::nullopt;
    int v = 0;
    for (char c : s) {
        if (c < '0' || c > '9') return std::nullopt;
        v = v * 10 + (c - '0');
    }
    return v;
}

Other limitations

  • No threads: std::thread, std::async and pthreads are unavailable.
  • No network, no fork/exec and no real file system, so std::ifstream cannot read files from your computer. Use stdin instead.
  • No graphics or GUI libraries such as Qt, SFML or OpenGL. Output is text only.
  • Third-party libraries like Boost are not installed. Everything must be in the single main.cpp file.

Modern C++ in a few lines

The starter program shows the idioms that make modern C++ shorter than older textbook code:

std::map<std::string, int> ages{ {"Ada", 36}, {"Linus", 54} };
for (const auto& [name, age] : ages)      // structured bindings
    std::cout << name << " is " << age << '\n';

std::vector<int> v{5, 3, 9, 1};
std::sort(v.begin(), v.end(), std::greater<>());
auto evens = std::count_if(v.begin(), v.end(), [](int x) { return x % 2 == 0; });
  • Prefer '\n' to std::endl in loops. endl also flushes the stream, which is slower.
  • When mixing std::cin >> n with std::getline, call std::cin.ignore() first, or getline reads the rest of the previous line as an empty string.
  • operator[] on a std::map inserts a default value when the key is missing. Use find or contains (C++20) to look a key up without changing the map.

Frequently asked questions

Which C++ standard is used?

C++20, compiled by Clang 21 with -O2 -Wall. Code written for C++11, C++14 or C++17 compiles as well.

Why does my code with try/catch not compile?

Exceptions are disabled with -fno-exceptions. Replace them with return values, std::optional or explicit checks before the risky operation.

Can I use bits/stdc++.h?

No. That header is specific to GCC and does not exist in libc++. Include the standard headers you need, such as <iostream>, <vector> and <algorithm>.

Is there a plain C version?

Yes, the online C compiler uses the same Clang in C17 mode. You can also browse every online compiler on the site.

Copied to clipboard