C++
v10.2.0
C++
v10.2.0
C++ is a statically typed, multi-paradigm language created by Bjarne Stroustrup at Bell Labs, beginning in 1979 as C with Classes and renamed C++ in 1983. It extends C with object-oriented programming, templates for generic code, RAII-based resource management, and a rich Standard Template Library. C++ aims to give high-level abstractions with little or no runtime overhead.
Today C++ powers game engines, high-frequency trading, browsers, databases, and other performance-critical software. Modern standards from C++11 onward added smart pointers, lambdas, move semantics, and more, making the language safer and more expressive. This compiler builds with GCC 10.2, which provides strong C++17 support and much of C++20, so you can use the STL, templates, and modern idioms directly in the browser.
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}#include <iostream>
#include <string>
int main() {
std::string name;
std::getline(std::cin, name);
std::cout << "Hello, " << name << "!" << std::endl;
return 0;
}#include <iostream>
#include <vector>
int main() {
std::vector<int> nums = {10, 20, 30};
for (int n : nums) {
std::cout << n << std::endl;
}
return 0;
}#include <iostream>
long factorial(int n) {
return n <= 1 ? 1 : n * factorial(n - 1);
}
int main() {
std::cout << factorial(5) << std::endl;
return 0;
}#include <iostream>
#include <stdexcept>
int main() {
try {
throw std::runtime_error("something failed");
} catch (const std::exception &e) {
std::cout << "Caught: " << e.what() << std::endl;
}
return 0;
}#include <iostream>
#include <map>
#include <string>
int main() {
std::map<char, int> counts;
for (char c : std::string("banana")) {
counts[c]++;
}
for (auto &[ch, n] : counts) {
std::cout << ch << ": " << n << "\n";
}
return 0;
}#include <iostream>
#include <vector>
#include <algorithm>
int main() {
std::vector<int> nums = {3, 1, 2};
std::sort(nums.begin(), nums.end());
for (int n : nums) std::cout << n << " ";
std::cout << "\n";
return 0;
}#include <iostream>
#include <string>
class Person {
public:
std::string name;
int age;
Person(std::string n, int a) : name(n), age(a) {}
void describe() const {
std::cout << name << " (" << age << ")\n";
}
};
int main() {
Person p("Ada", 36);
p.describe();
return 0;
}#include <iostream>
template <typename T>
T maxOf(T a, T b) {
return a > b ? a : b;
}
int main() {
std::cout << maxOf(3, 7) << "\n";
std::cout << maxOf(2.5, 1.5) << "\n";
return 0;
}#include <iostream>
#include <vector>
#include <algorithm>
int main() {
std::vector<int> nums = {1, 2, 3, 4, 5};
int count = std::count_if(nums.begin(), nums.end(),
[](int n) { return n % 2 == 0; });
std::cout << "Evens: " << count << "\n";
return 0;
}Yes. CompileBytes compiles and runs C++ in your browser without a local compiler or IDE.
Your code is built with GCC 10.2, which fully supports C++17 and much of C++20, including most of the STL.
Read from std::cin (using >> or std::getline) and type your input into the stdin box before running.
Yes, compiling and running C++ on CompileBytes is free of charge.
GCC 10.2 defaults to a recent standard, and you can rely on C++17 features; many C++20 features such as concepts and ranges are also available.