Skip to content
Devtoolry

C++ Compiler

Compile and run C++20 code online with Clang 21, libc++ and stdin input. Programs compile to WebAssembly and run in your browser, so your code stays private.

About the C++ Compiler

The online C++ Compiler builds your code with Clang 21 and libc++ in C++20 mode and runs it in your browser. Test an algorithm, try ranges, structured bindings or templates, or check competitive-programming solutions against sample input, without setting up a toolchain.

Your code runs in an isolated Web Worker in your browser, so it never leaves your device.

How to use the C++ Compiler

  1. Write or paste a C++ program with a main() function.
  2. Put the input your program reads with std::cin or getline in the stdin box.
  3. Click Run. The first run downloads the compiler (about 23 MB); later runs reuse it.
  4. Fix any compiler errors (they show the line and column), then read the output.

Example

Count words from standard input

Input

#include <iostream>
#include <map>
#include <sstream>
#include <string>

int main() {
    std::map<std::string, int> counts;
    std::string line, word;
    while (std::getline(std::cin, line)) {
        std::istringstream words(line);
        while (words >> word) ++counts[word];
    }
    for (const auto& [w, n] : counts) std::cout << w << ' ' << n << '\n';
}

Result

cat 1
dog 1
end 1
saw 1
the 3

With "the cat saw the dog" and "the end" in the stdin box. std::map keeps the keys sorted.

Common mistakes

  • Exceptions end the program. The WebAssembly C++ runtime here has no exception support: a throw prints "terminate called after throwing an instance of …" and aborts, even inside try/catch. Check inputs before calling functions such as std::stoi or vector::at, or return error codes.
  • #include <bits/stdc++.h>. That header only exists in GCC. Include the standard headers you use, for example <iostream>, <vector>, <algorithm>, <map> and <string>.
  • Slow first compile. Standard library headers such as <iostream> take a few seconds to compile in the browser. Compilation does not count toward the program’s time limit.

Works well with the C++ Compiler

  • C Compiler: run plain C programs, which compile in a fraction of a second.
  • Python Compiler: prototype an algorithm in Python before writing it in C++.
  • Text & Code Diff: compare the output with the expected answer.

Frequently asked questions

Which C++ version is supported?

C++20 with Clang 21 and libc++ (-std=c++20 -O2 -Wall): concepts, ranges, std::span, structured bindings, constexpr algorithms and std::format all work.

Are exceptions supported?

Code with try, catch and throw compiles, but a thrown exception ends the program with a "terminate called after throwing" message instead of being caught, because the WebAssembly runtime has no exception support.

Is it g++?

It is clang++ with libc++, LLVM’s standard library. It accepts standard C++ and most GCC extensions, but GCC-only headers such as bits/stdc++.h are not available.

Can I use it for competitive programming?

Yes, for testing solutions against sample input: paste the input into stdin and compare the output. Performance is close to native for loops and arithmetic, but judges’ time limits are measured on their own machines.

Is my code sent to a server?

No. The compiler runs in your browser as WebAssembly, and so does your program, so the code never leaves your device.