Playcode Classic

C++ Playground

This C++ playground is a C++ sandbox that compiles your code in your browser, with Clang and C++20. Write it, press Run and read the output, or the compiler’s errors, in the console. Nothing to install and no account to start. Sign in to save and share a link. It’s part of Playcode Classic, Playcode’s free code tools.

Free. No account needed to start.

Play wheels a wobbling tower of boxes and manuals out of a playground sandbox on a hand truck, while a student already codes in the sand with her laptop, the console showing a green tick.

What this C++ playground compiles

CompilerClang, compiled to WebAssembly, running in your browser
StandardC++20, with -O2 and warnings on (-Wall -Wextra)
LibraryContainers, strings, algorithms and streams; #include <bits/stdc++.h> works
Filesmain.cpp is compiled; other files aren’t yet
Input (cin)Not yet: put the values in your code
ExceptionsOff: code that throws doesn’t compile
ErrorsClang’s errors and warnings, in the console
StopEnds any program, an endless loop included
RunCtrl+R
PhoneYes, in your phone’s browser

Errors a page long? The AI reads them for you.

Clang says what went wrong, sometimes at length. Ask the editor’s AI chat: it already sees the errors in your console, then explains them or fixes the code. It uses credits; eligible new accounts get trial credits.

An enormously long paper scroll of error lines winds round a playground with Play tangled in it; its end reaches the student’s laptop on a bench, and she holds up the short card that came out: one line and a green tick.

C++ to try

Sort and print
#include <bits/stdc++.h>
using namespace std;

int main() {
  vector<int> scores =
    {72, 95, 61, 88};
  sort(scores.begin(),
       scores.end(),
       greater<int>());
  for (int s : scores)
    cout << s << ' ';
  cout << '\n';
}
Console
95 88 72 61
A template function
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

template <typename T>
T total(
  const std::vector<T>& items
) {
  return std::accumulate(
    items.begin(),
    items.end(), T{});
}

int main() {
  std::cout << total(
    std::vector<int>{1, 2, 3})
            << '\n';
  std::cout << total(
    std::vector<double>{
      0.5, 1.25})
            << '\n';
  std::cout << total(
    std::vector<std::string>{
      "C", "++"})
            << '\n';
}
Console
6
1.75
C++
Structured bindings
#include <iostream>
#include <map>
#include <string>

int main() {
  std::map<std::string, int>
    stock = {{"apples", 4},
             {"pears", 0}};
  for (const auto&
       [name, count] : stock) {
    std::cout
      << name << ": "
      << (count ? "in stock"
                : "sold out")
      << '\n';
  }
}
Console
apples: in stock
pears: sold out
At a playground sand table Play presses a star-shaped cutter into wet sand beside a row of sand stars, and the student presses the same cutter into blue modelling clay.

Part of Playcode Classic

Playcode began in 2016 as a browser coding environment. This playground is one of its free code tools, which we now call Playcode Classic.

Playcode today is an AI platform for building and running websites and apps.

Play stands at the open gate of an old playground and presents what lies beyond it: a rocket ready on its launch pad.

Questions people ask

  • Is this online C++ playground free?

    Yes. Compiling and running code is free and needs no account. Saving and sharing need a free account, which keeps up to three saved projects, public or private; the AI chat uses credits.

  • Which compiler and C++ version does it use?

    Clang, compiled to WebAssembly, running in your browser. It compiles C++20 with -O2, -Wall and -Wextra.

  • Do I need to install a compiler?

    No. Open it in a browser on a computer or a phone and press Run.

  • Can my program read input with cin?

    Not yet. The playground can’t pass typed input to your program. Put the values in your code instead.

  • Can I use exceptions?

    Not yet. The playground compiles with exceptions turned off, so code that throws doesn’t compile.

  • Does #include <bits/stdc++.h> work?

    Yes.

  • Can I split my program into several files?

    Not yet. The cpp playground compiles one file, main.cpp.

  • How is this different from the C++ compiler?

    Both open the same editor and compiler. Use this page to try ideas; use the C++ compiler page to compile a program and read its output.

  • Can I run C instead?

    Yes, in the C compiler, which runs C in your browser the same way.

  • Is this playground part of Playcode?

    Yes. This playground is part of Playcode Classic, Playcode’s free code tools. Playcode began in 2016 as a browser coding environment. Today it is an AI platform for building and running websites and apps.

More free code tools

Write some C++. Press Run.

A rocket waits with its door open and an empty seat, and Play invites you in. High above, another rocket climbs away.