#include <iostream>

int main() {
    std::cout << "Welcome to Online IDE!" << std::endl;
    std::cout << "Start coding in C++..." << std::endl;
    int a, b;
    std::cout << "Enter a number: ";
    std::cin >> a;
    std::cout << "Enter another number: ";
    std::cin >> b;
    std::cout << "The sum of " << a << " and " << b << " is " << a + b << std::endl;
    return 0;
}

Press Run or Ctrl ↵ to execute main.cpp.
Type program input here while it runs.

C++

Online C++ IDE

A C++ project keeps headers, sources and data files together in folders, saved to your account, and builds with G++ 16 like the playground: every .cpp file at the top of the project goes into one program. The C++ standard is set per project in Project details.

Try it above

How C++ runs here

Versions
C++98, 11, 14, 17 (default), 20, 23, 26 preview, G++ 16
Build
g++ -O2 -std=gnu++17 -o a.out *.cpp
Run
./a.out
Limits per run
256 MB memory, 15 s of CPU time on 2 cores, 2 MB of output
Time
Up to 10 minutes a run (30 on a paid plan); waits 2 minutes for input (5 on a paid plan)
Sandbox
Each run gets its own Linux sandbox with no network access. Text files your program writes next to your code open as new tabs.
Good to know
Every .cpp file is compiled together; bits/stdc++.h is precompiled.

A project with headers and data

Files
main.cpp
geometry.cpp
include/geometry.hpp
data/rects.txt
C++
// include/geometry.hpp
#pragma once
#include <vector>

struct Rect {
    double w, h;
};

double area(const Rect &r);
std::vector<Rect> read_rects(const char *path);

// geometry.cpp
#include "include/geometry.hpp"
#include <fstream>

double area(const Rect &r) { return r.w * r.h; }

std::vector<Rect> read_rects(const char *path) {
    std::ifstream in(path);
    std::vector<Rect> rects;
    for (Rect r; in >> r.w >> r.h;) rects.push_back(r);
    return rects;
}

// main.cpp
#include <iostream>
#include "include/geometry.hpp"

int main() {
    auto rects = read_rects("data/rects.txt");
    double total = 0;
    for (const auto &r : rects) total += area(r);
    std::cout << rects.size() << " rectangles, total area " << total << '\n';
}
Text
# data/rects.txt
3 4.5
2 2
10 0.5
Terminal
$ ./a.out
3 rectangles, total area 22.5

The program runs from the top of the project, so data/rects.txt opens with that relative path.

Where .cpp files can go

  • The build compiles the .cpp files at the top of the project, as g++ … *.cpp does. Move geometry.cpp into src/ and it’s no longer compiled, so the link fails with undefined reference to `read_rects(char const*)'.
  • Headers and data can live in any folder. Include headers by their path from the including file, as in #include "include/geometry.hpp", since the build adds none of your folders to the include path.
  • Only one top-level .cpp file may define main(). A second program, such as a test-data generator, can live in its own folder and run from the Premium terminal (below).
  • Files the program writes come back into the project. std::ofstream doesn’t create folders, so call std::filesystem::create_directories("out") before writing out/result.txt.

Working in a C++ project

  • Ctrl+P opens a file by typing part of its name (geo finds include/geometry.hpp and geometry.cpp), Ctrl+B shows or hides the file tree, and Alt+W closes the open file.
  • Upload input files into data/ or any folder, and download the whole project as a .zip.

What a C++ project doesn’t have

  • CMake and make: Run ignores CMakeLists.txt and Makefile and compiles the top-level .cpp files.
  • gdb or another debugger: stepping through code is for Python only. Print to std::cerr, whose lines show in red, to trace values.
  • A C++ language server: completion suggests words from the open file, not class members.
  • Third-party libraries such as Boost or fmt: only the standard library and GCC’s extensions.

Plans for C++ projects

  • Free accounts get 3 public projects of up to 3 MB. Basic allows unlimited private projects of up to 25 MB, shared with people you choose, and forking; Premium raises the size to 100 MB (see Pricing).
  • Premium starts a Linux session per project with a terminal that keeps running. There you can build your own way, such as g++ -O2 -Iinclude -o app main.cpp src/*.cpp && ./app, and run tools/gen.cpp builds the .cpp files in tools/ into a separate program and runs it.
  • On Basic and Premium the agent takes a task such as “split geometry.cpp into one file per shape”, edits the files, builds and runs the program, fixes what fails, and shows every change as a diff you can undo.

Questions

Why do I get undefined reference after moving files into src/?

Only .cpp files at the top of the project are compiled. Move them back up, or build with your own command in the Premium terminal.

Can I use CMake?

Run doesn’t read CMakeLists.txt or a Makefile; it compiles every top-level .cpp file with G++ 16.

Is there a C++ debugger?

No. The step debugger is for Python only; trace C++ with std::cerr.

Which compiler and standard does a project use?

G++ 16, with the standard chosen in Project details: C++98, 11, 14, 17, 20, 23 or the C++26 preview.

How do I read a data file?

Upload it into the project and open it with a path from the top, such as std::ifstream in("data/rects.txt").