C++ Playground

C++ code

Options

Choosing an example replaces code and input, and pauses Auto-run. Multiline code requires confirmation.

The first Run downloads the language runtime from jsDelivr. Ctrl/Cmd + Enter runs code. Monaco loads from a CDN only when enabled.

Plain editor

Interactive input waits for each answer in the console. Requires HTTPS and service workers; no backend and no persisted input.

0 lines · 0 chars

Monaco offers word suggestions (Ctrl + Space), plus JavaScript/TypeScript syntax and type diagnostics. Other languages have limited suggestions; check errors after Run. Suggestions need Monaco.

Console

You can type ahead. Enter sends a line when the program asks; EOF ends input. Answers are echoed in the console, not saved.

Timing measures elapsed time, not CPU time; waiting for input is included. WASM memory, when available, is linear memory capacity, not total RAM or peak usage.

Read terminal input with std::cin or std::getline. Runs in a Web Worker, without direct DOM access. Stop terminates execution; execution outside input waits is limited to 30 seconds, each answer can wait up to 2 minutes, and output is capped at 500 rows. Code can still make network requests, so only run code you trust. The tool does not save or upload your code or input.

Replace existing code?

Loading will replace the current code and input. Cancel to keep your work.

Runtime details

Interactive stdin installs a service worker scoped to /tools/ on its first Run. It answers only reserved input requests locally, without caching pages or persisting answers. If unavailable, use Prepared standard input. This is line-based input, not a shell or full terminal emulator.

The browsercc 0.1.1 Clang/LLD toolchain downloads from jsDelivr on the first Run — roughly 26 MiB compressed for clang.wasm, lld.wasm and the sysroot. Code is compiled to WebAssembly, then run in a fresh Worker. Use interactive terminal input, or prepare standard input before Run. C++ exceptions and threads are unavailable in this WASI toolchain. Runtime notices.

Learn

C++ Playground Guide

About this tool

Compile C++20 to WebAssembly in a disposable browser Worker with the browsercc 0.1.1 Clang/LLD toolchain. The compiler and sysroot download from jsDelivr only on Run or when Auto-run is enabled. Exercises cover arithmetic, logic, containers, classes and pyramid patterns. Code and input are not saved or uploaded by the tool. Compiled code can still make network requests through WASI; only run code you trust.

Questions

How do I read input?
In Interactive terminal mode, std::getline or std::cin waits for an answer in the console. Enter sends a line; EOF (or Ctrl + D) ends the stream. getline drops the newline and returns false at EOF. Prepared standard input remains available before Run.
Why does the first Run take longer?
The Clang compiler, linker and sysroot download from jsDelivr on the first Run — roughly 26 MiB compressed. Runtime loading has a 90-second timeout, followed by a 30-second execution limit outside input waits. Each answer can wait up to 2 minutes. Later Runs in the same page reuse the loaded toolchain.
Can I use exceptions, threads or the full standard library?
No. The WASI libc++ is built without exceptions or threads, and this runner compiles with -fno-exceptions. Code that relies on throwing or catching will not link. Most of the standard library for console programs, including string, vector and map, works.
Does selecting an example erase my code?
Yes. Selecting immediately replaces code and standard input, and pauses Auto-run. If the editor contains more than one line, confirm deletion of existing code or cancel to keep code and input.
Is this a security sandbox?
No. A Worker prevents direct DOM access and can be terminated, but compiled code can make network requests through WASI. The tool itself does not upload or persist code or input. Each Run starts fresh; output is limited to 500 rows.