C++ Compiler

Code
Output

        

What Is the C++ Online Compiler?

This tool lets you write, compile, and run C++ programs directly in your browser without installing a compiler or IDE on your machine. It is built for students, hobbyists, and experienced developers who need a quick way to test modern C++ code online.

The compiler supports modern C++ standards and gives you access to the full C++ Standard Library, including containers, algorithms, and I/O streams. Your code is sent to the Piston execution engine, which compiles it with GCC (g++) inside a sandboxed container and returns the output to your browser within seconds.

You can provide standard input through the STDIN field and pass command-line arguments through the Args field, making it easy to simulate realistic program execution without leaving the browser.

How It Works

  1. Write your C++ code in the editor panel. The editor starts with a simple "Hello, C++!" example that demonstrates basic output and command-line argument handling, but you can replace it with any valid C++ program.
  2. Provide input in the STDIN field if your program reads from std::cin or scanf. Each line in the STDIN box becomes a line of standard input available to your program. Leave this field empty if your program does not require input.
  3. Add command-line arguments in the Args field if your program reads from argv. Enter arguments separated by spaces, just as you would on a terminal.
  4. Click the Run button to send your code to the Piston server. The server compiles your source file with g++ and then executes the resulting binary.
  5. View the results in the Output panel. If compilation succeeds, you see your program's standard output. If there are compile errors, the compiler diagnostics appear instead, showing the line numbers and error descriptions so you can fix the issue and try again.

Step-by-Step Example

Suppose you want to write a program that reads a name from standard input, prints a greeting using std::cout, and demonstrates an STL container. Here is how you would do it:

First, type the following code into the editor panel:

#include <iostream>
#include <string>
#include <vector>

int main() {
    std::string name;
    std::cin >> name;
    std::cout << "Hello, " << name << "!" << std::endl;

    std::vector<int> nums = {10, 20, 30};
    for (int n : nums) {
        std::cout << n << " ";
    }
    std::cout << std::endl;
    return 0;
}

Next, go to the STDIN field and type a name, for example Alice. This value will be read by the std::cin call when the program runs.

Now click the Run button. The compiler sends your code and the STDIN data to the execution server. After compilation and execution, the Output panel displays:

Hello, Alice!
10 20 30

The program reads the name from standard input, prints the greeting, and then iterates over a std::vector to print its contents. If you change the STDIN value or modify the vector, clicking Run again shows updated results instantly.

Use Cases

Limitations and Notes

Frequently Asked Questions

What C++ standard is supported?

Typically C++17 or later via GCC.

Can I use STL containers and algorithms?

Yes, the full C++ Standard Library is available.

Can I use cin for input?

Yes, enter input in the STDIN field.

Are there external libraries like Boost?

No, only the C++ Standard Library.

Can I use templates and classes?

Yes, all C++ language features are supported.

Is there a compilation step?

Yes, code is compiled first. Errors show in output.

Can I create multiple files?

No, single file (main.cpp) compilation only.

What compiler is used?

GCC (g++) via the Piston execution engine.

Sources and References

Related Compilers