Back to the blog

Developer

Compile and run C++ in your browser, STL included.

Compile and run C++20 in your browser with clang and libc++, nothing uploaded: cin reading an Input box, the STL, and errors at their line.

By 4 min read

A code playground: an editor on the left, what the program printed on the right, and its console underneath

To try a few lines of C++ you normally need a compiler and a build. The KeepSimp code playground has clang and libc++ inside your browser: your program is compiled to WebAssembly on your device and run there, with nothing to install and nothing uploaded.

Write, press Run, read what it prints.

Open the C++ compiler online and press Start with C++. Write your program and press Run, or Ctrl or ⌘ and Enter. clang compiles it as C++20 with -O2 and -Wall, and what std::cout prints appears in the result and in the console.

std::cin reads the Input box under the editor, as an online judge gives a program its input: write what it should read, then press Run. The first run downloads the compiler, about 21 MB, kept by your browser for working offline.

The standard library is there.

vector, map, string, algorithm, iostream and the rest come from libc++, LLVM's own standard library. The starters show a class with private data, and words read from the Input box, sorted and counted with the STL.

Exceptions are not: the libc++ built for WebAssembly here has no support for them, so throw and try do not compile, and the error says so beside its line. std::optional or an error value does the same job.

Errors at their line, crashes in words.

clang's messages are shown as it wrote them, and the console links each error to its line in the editor or in another file of the project. A plain hint is added only where one is sure, such as std::cout written without std.

When a program crashes, the browser's words are put into plain ones, with the function it happened in, its C++ name made readable: memory past the end of a buffer, a stack that ran out, a division by zero or abort().

What it is, and what it is not.

It is clang from LLVM 22 compiling to WebAssembly, and the program runs under WASI in a worker of its own, not on an operating system: there are no threads or sockets, and files the program writes last only while it runs. Other .cpp files and headers in Files are compiled and included with the editor's.

Press Stop in the result to end a program that never finishes; one that runs for a minute is stopped and says so.

Further reading

Topics: c++ compiler online · cpp compiler online · run c++ online · online c++ compiler · c++20 online · clang online

A little less theory. A little more doing.

Try it on your own terms, with a free browser tool.

Try the tool