Write C++ and run it in seconds. This online C++ compiler builds your code with G++ 14 in C++17 mode with optimisation (-O2), then runs it in a secure sandbox on the K-Programmer engine. The whole standard library is there: iostream, string, vector, map, algorithm, bits/stdc++.h and more.
Give your program input for cin and getline in the Input box, the same way competitive programming judges do. Start from one of the samples (hello world, input, loops, vectors, functions, the Sieve of Eratosthenes), and your code is saved automatically in your browser.
How to use the C++ Online Compiler tool
- Choose a sample or type your own C++ program.
- Enter the input for
cinin the Input box, one value per line or separated by spaces. - Click Run or press Ctrl+Enter to compile and run.
- Check the output and the compiler messages, then edit and run again.
- Use Share code for a link, or Open in K-Programmer to practise with graded exercises.
Why use ToolOrca C++ Online Compiler
- G++ 14 with C++17 and
-O2, the full STL andbits/stdc++.h - Standard input for
cin,getlineandscanf - Clear compile errors, runtime errors, exit code and run time
- Editor with syntax colours, line numbers, auto-indent and Ctrl+Enter
- Six samples including the Sieve of Eratosthenes
- Autosave and share links; nothing to install
Using cin and getline online
Type all input before you run. cin >> x skips spaces and new lines, so 3 4 on one line and 3 and 4 on two lines work the same. getline(cin, s) reads a whole line; after cin >> n call cin.ignore() first to skip the rest of that line.
For speed with large input, add ios::sync_with_stdio(false); cin.tie(nullptr); at the start of main, as competitive programmers do.
Compiler flags and limits
The command is g++ -O2 -std=c++17 main.cpp. Programs get 5 seconds, 512 MB of memory and no network, in a fresh sandbox that is removed after the run. Output is shown up to a generous size limit.
Exit code -11 (“Segmentation fault”) means a crash, for example v[i] outside the vector or very deep recursion; exit code -6 usually means an uncaught exception or a failed assertion. Use v.at(i) while debugging to get a clear error instead.
From practice to contests
The samples cover what most C++ courses start with: output, input, loops, vectors and the STL algorithms, references and overloading, and a classic algorithm.
To solve problems that are checked automatically against hidden tests, or to join timed contests, continue in K-Programmer.
Frequently asked questions
Which C++ version is supported?
C++17, compiled with G++ 14 (-std=c++17 -O2).
Can I use bits/stdc++.h?
Yes. The compiler is GCC on Linux, so #include <bits/stdc++.h> works, as on most judges.
Why does my program not wait for input?
Online, input is given before the run. Type it in the Input box, then click Run. If the input runs out, cin fails and later reads return nothing.
How do I share my code?
Click Share code. The link that is copied contains your code and input, compressed, after the # sign, so nothing is stored on a server and the link works as long as you keep it.
What is "Open in K-Programmer"?
K-Programmer is a free platform for learning to code, with lessons, quizzes, contests and the same online compiler. The button copies your code and opens K-Programmer, where you choose the language, paste the code and keep working (sign in to save programs).