# C++ Playground

Compile and run C++ in your browser with a WASI Clang toolchain, prepared standard input, console output and coding examples.

## URL

https://ilham.dev/tools/cpp-playground/

## What It Does

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.

## Features

- Browser-side Clang compile to WebAssembly
- Prepared standard input
- Run and Stop
- Coding exercises and pyramid patterns

## Input

C++ source with optional prepared standard input c++ input.

## Output

Program standard output and standard error plus compiler diagnostics console output.

## Privacy

Processing happens locally in the browser.

No input data is uploaded to ilham.dev.

- Requires login: false
- Requires API key: false
- Stores user data: false


## Examples

- How do I read input?
- Why does the first Run take longer?
- Can I use exceptions, threads or the full standard library?
- Does selecting an example erase my code?
- Is this a security sandbox?


## Limitations

- The Clang/lld toolchain and sysroot download from jsDelivr on Run; roughly 26 MiB compressed.
- The WASI standard library is built without exceptions or threads; a fresh Worker is created for each run.
- Prepared input is not a live interactive terminal.
- Worker execution is not a security sandbox; code can make network requests.
- Execution is limited to 30 seconds after compilation and 500 output rows.


## Related Tools

- https://ilham.dev/tools/c-playground/
- https://ilham.dev/tools/javascript-playground/
- https://ilham.dev/tools/typescript-playground/
- https://ilham.dev/tools/python-playground/
- https://ilham.dev/tools/ruby-playground/


## Questions

### How do I read input?

Fill Standard input before Run, one answer per line, then use std::getline or std::cin. std::getline drops the trailing newline for you. If the stream is empty, getline returns false. This is prepared input, not a live terminal.

### 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 separate 30-second execution limit. 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. C++ examples are complete programs with their own main, so clicking one replaces the editor and pauses Auto-run. Copy anything you want to keep first.

### 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.

