Online C++ Compiler
Run C++ code online for free: compile C++20 with Clang 21 and libc++, type stdin input and see the output. It runs in your browser, so your code stays private.
Runs in your browser · Nothing uploaded · No sign-up
Something not working, or missing a feature? Send feedback
About the C++ Compiler
Run C++ code online with this free C++ compiler. It builds your program with Clang 21 and libc++ in C++20 mode, then runs it with the input you type. Use it to test an algorithm, try ranges or templates, or check a competitive-programming solution against sample input. You don't need to install g++, Visual Studio or an IDE. The editor has syntax highlighting, so it works like a small online C++ IDE for code snippets and test cases. The compiler runs in your browser as WebAssembly, so your code is never uploaded.
Your code runs in an isolated Web Worker in your browser, so it never leaves your device.
How to use the C++ Compiler
- Write or paste a C++ program with a main() function.
- Put the input your program reads with std::cin or getline in the stdin box.
- Click Run. The first run downloads the compiler (about 23 MB); later runs reuse it.
- Fix any compiler errors (they show the line and column), then read the output.
Example
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.
- Relying on <bits/stdc++.h>. It works here (it includes the common standard headers), but it is a GCC convenience header that MSVC and Apple Clang do not have. For code you will build elsewhere, include the headers you use, such as <iostream>, <vector> and <algorithm>.
- Slow first run. The first run downloads the compiler and parses the standard headers, which takes a few seconds. Precompiled headers then load in the background, and later runs usually compile in one to three seconds. 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.
What does a minimal C++ program look like?
Start with #include <iostream>, then write int main() { std::cout << "Hello\n"; return 0; }. The return 0 is optional in main: when main ends without a return statement, the program exits with status 0 (success).
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, and #include <bits/stdc++.h> works too.
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.
How do I read a whole line with spaces in C++?
Use std::getline(std::cin, line). cin >> word stops at whitespace, and mixing the two leaves a newline in the buffer, so call std::cin.ignore() before getline. Our reading input in C and C++ guide covers it.
What is the difference between g++ and clang++?
They compile the same C++ and share most flags. clang++ gives more direct error messages and uses libc++ here; g++ uses libstdc++ and supports a few GNU-only extensions. See the GCC vs Clang guide for real output from both.
Can I use C++20 features such as ranges and concepts?
Yes. The compiler runs in C++20 mode, so concepts, ranges, std::span, designated initializers and the three-way comparison operator work.
Which online C++ compiler is best?
It depends on the job. For debugging with breakpoints, a site such as OnlineGDB fits; for comparing compilers and reading assembly, Compiler Explorer. This compiler suits practice, interviews and competitive programming: C++20 with Clang 21, stdin input, no sign-up, and your code stays in your browser.
Does it compile C++17, C++14 and C++11 code?
Yes, in almost every case. Programs are built in C++20 mode, and C++20 keeps the features of C++17, C++14 and C++11, so code written for those standards compiles unchanged unless it relies on something later standards removed, such as std::auto_ptr.
Is it free, and do I need an account?
It is free and needs no account. Runs can take up to 5 seconds on the free plan; Pro raises the limit to 15 seconds and removes ads.
Guides and tutorials
- Programming Languages
How to Run C++ Code Online: Compile C++20 with Input in Your Browser
Run C++ code online with C++20: compile a first program, feed stdin, use vectors and structured bindings, read g++ errors and avoid the common beginner traps.
· 4 min read
- Programming Languages
Reading Input in C and C++: scanf, cin and getline Explained
Why getline returns an empty string after cin, how to read until end of input, validate numbers, read lines safely in C and speed up input, with tested code.
· 6 min read
- Programming Languages
-O0 vs -O2 vs -O3: GCC and Clang Optimization Levels Benchmarked
What -O0, -O1, -O2, -O3, -Os, -Ofast and -march=native really do, measured with GCC and Clang on five C programs: run time, code size and compile time.
· 10 min read
- Programming Languages
GCC Command Line Options Explained: -o, -c, -Wall, -std, -O2, -g and -lm
The GCC options you use every day, with real output from GCC 11: naming the output, compiling in steps, warnings, -std, -O levels, -g, -I, -D and -lm.
· 9 min read
- Programming Languages
malloc vs calloc in C: Which Is Faster? We Measured
malloc vs calloc measured on Linux: fresh vs reused memory, where zeroing really happens, why compilers turn malloc + memset into calloc, and overflow checks.
· 9 min read
- Programming Languages
How to Compile and Run C Code Online (No Install, With Input)
Compile and run C code online in your browser: a first program, reading stdin input, choosing a C standard from C89 to C23, and fixing common errors.
· 4 min read
Related tools
JavaScript Compiler
Run JavaScript online in an isolated browser sandbox. See console output, errors and execution time instantly, with top-level await and stdin input.
TypeScript Compiler
Compile and run TypeScript online. Your code is type-checked with the official compiler in strict mode, then runs in a sandboxed worker in your browser.
Python Compiler
Run Python 3 code online with the full standard library and stdin input. It runs in your browser with Pyodide (WebAssembly), so your code stays on your device.
PHP Compiler
Run PHP 8.4 code online and see the output instantly, with stdin input and mbstring. PHP runs in your browser with WebAssembly, so your code stays private.
C Compiler
Compile and run C code online with Clang 21, a GCC-compatible compiler: pick C89 (ANSI C), C99, C11, C17 or C23 and add stdin input. Your code stays private.
C# Compiler
Run C# code online with Roslyn and .NET 10: C# 14, top-level statements, LINQ, records and Console.ReadLine input, in your browser, so code stays private.