Online C++ Compiler
Run C++ programs with the full STL. Good for DSA practice and coding rounds.
About this C++ compiler
This online C++ compiler uses G++ 10 on our server. You can use the Standard Template Library (STL): vector, map, set, sort and more. Press Run and type the input for cin in the terminal when the program asks.
Most competitive programmers in India use C++, so this page is set up for that work: fast compile, clear errors and the real running time of your program.
How to use it
- Write your program with a main() function.
- Add #include <bits/stdc++.h> or the headers you need.
- Press Run, then type the input for cin in the terminal and press Enter.
C++ examples
Open any of these from the Examples tab in the side bar.
Hello, World
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
Sort numbers with the STL
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int &x : v) cin >> x;
sort(v.begin(), v.end());
for (int x : v) cout << x << " ";
cout << endl;
return 0;
}
Count words with a map
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> words = {"code", "run", "code", "learn", "run", "code"};
map<string, int> count;
for (auto &w : words) count[w]++;
for (auto &[word, n] : count) cout << word << ": " << n << endl;
return 0;
}
What is C++?
C++ is C with more features: classes, templates and a large standard library. It is fast, so it is used for games, trading systems, browsers and competitive programming.
For data structures and algorithms (DSA), the STL saves a lot of time. A vector is a list that can grow, a map stores key–value pairs in sorted order, and sort() sorts any range.
Common errors and how to fix them
'cout' was not declared in this scopeAdd using namespace std; or write std::cout.no matching function for call to …The types you passed do not match the function. Check the argument types.Took too longYour algorithm may be too slow for the input. Check for nested loops over large data.
Frequently asked questions
Which C++ standard is used?
G++ 10.2 with its default standard, which supports C++17 features such as structured bindings and auto.
Can I use bits/stdc++.h?
Yes. #include <bits/stdc++.h> works, because the compiler is G++.
How do I give input to cin?
Type it in the terminal while the program runs, and press Enter. You can also type all input in the Input box before you press Run, the same way an online judge gives input.
Is it free?
Yes. You can run code without an account. A free account gives you higher limits.
Why does my program say "Took too long"?
Without an account, each run can use 3 seconds of computer time. A loop that never ends or a very slow algorithm will stop at that limit. A program that is waiting for your input can wait up to 30 seconds.
Other free compilers
Learn to code with DevHives
Step-by-step lessons, DSA problems with a judge and mock interviews — made for students in India.
Create a free account