Skip to main content

C++

C++ is a general-purpose programming language with a bias towards systems programming. It supports procedural, object-oriented, and generic programming paradigms.

LiveCodes runs C++ in the browser using JSCPP, a C++ interpreter written in JavaScript that runs in a Web Worker.

Usage

Demo

show code
import { createPlayground } from 'livecodes';

const options = {
"template": "cpp"
};
createPlayground('#container', options);

Standard I/O

C++ programs in LiveCodes use cin for input and cout for output. Input is passed from JavaScript via livecodes.cpp.run(), and output is returned as a string.

JavaScript Interoperability

JavaScript can interact with the C++ runtime using the livecodes.cpp global:

  • livecodes.cpp.input — set this to pass input to the program (read by cin)
  • livecodes.cpp.run(input?) — execute the C++ program with optional input, returns a promise that resolves to { input, output, exitCode, error }
  • livecodes.cpp.loaded — a promise that resolves when the runtime is ready

Language Info

Name

cpp

Extensions

.cpp, .c, .C, .cp, .cxx, .c++, .cppm, .ixx, .ii, .hpp, .h

Editor

script

Compiler

JSCPP (C++ interpreter)

Code Formatting

Not supported.

Starter Template

https://livecodes.io/?template=cpp