g++ 11 · C++17

C++ compiler API

Compile and run user-submitted C++ with one HTTPS request. CodeForge compiles with g++ 11 in C++17 mode with -O2, runs the binary in an isolated sandbox, and returns compiler output, stdout, stderr and the exit code.

Example: run C++ with one request

Submit the source and stdin, then poll GET /v1/executions/{id} until it finishes.

The program
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int n; std::cin >> n;
    std::vector<int> v(n);
    for (auto &x : v) std::cin >> x;
    std::sort(v.begin(), v.end());
    for (int x : v) std::cout << x << " ";
    std::cout << std::endl;
}
The request
curl -X POST https://api.tatvastack.com/v1/executions \
  -H "Authorization: Bearer $CODEFORGE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"language":"cpp","source":"#include <iostream>\n#include <vector>\n#include <algorithm>\n\nint main() {\n    int n; std::cin >> n;\n    std::vector<int> v(n);\n    for (auto &x : v) std::cin >> x;\n    std::sort(v.begin(), v.end());\n    for (int x : v) std::cout << x << \" \";\n    std::cout << std::endl;\n}","stdin":"5\n4 1 5 2 3"}'
The result
{
  "executionId": "exe_…",
  "status": "SUCCEEDED",
  "language": "cpp",
  "stdout": "1 2 3 4 5 \n",
  "stderr": "",
  "compileOutput": "",
  "exitCode": 0,
  "durationMs": …
}
FAQ

C++ execution questions

Which C++ standard and compiler flags are used?

g++ 11 with -std=c++17 -O2.

How do I detect a segmentation fault?

The execution returns status RUNTIME_ERROR with a non-zero exitCode instead of hanging or failing the request.

Is bits/stdc++.h available?

Yes, the GNU standard library headers are included with g++.

Are fork bombs and memory bombs contained?

Yes. Process, memory, file and time limits are enforced on every run, and a sandbox that cannot be verified clean afterwards is discarded.

Run C++ in your product today

500 free runs a month during the beta. No servers to manage.

Read the quickstart Request beta access