JSCPP for LiaScript: Run C++ Directly in the Browser Without a Compiler

JSCPP for LiaScript: Run C++ Directly in the Browser Without a Compiler

C++ programming courses have a tooling problem. Students need to install a compiler, configure an IDE, manage build systems, and debug their environment before writing a single line of code.

The JSCPP template removes all of that. Based on JSCPP, a JavaScript implementation of a C++ interpreter, it makes C++ code blocks in your LiaScript course directly executable — no compiler installation, no server, no configuration.


Quick Start

<!--
import: https://raw.githubusercontent.com/liaTemplates/JSCPP/master/README.md
-->

Two macros are available: @JSCPP.eval for standard execution and @JSCPP.evalWithStdin for programs that read from standard input.


Macro 1: @JSCPP.eval — Execute C++ Code

Attach @JSCPP.eval to any C++ code block to make it executable and editable. The code is evaluated by the JSCPP interpreter; cout output and errors appear in the console below.

```c
#include <iostream>
using namespace std;

int main() {
  for (int i = 1; i <= 5; i++) {
    cout << i << "^2 = " << i * i << endl;
  }
  return 0;
}
```
@JSCPP.eval

Line numbers are shown in error messages, making it easy to find and fix mistakes.


Macro 2: @JSCPP.evalWithStdin — C++ with Standard Input

Many C++ exercises involve reading input. Use @JSCPP.evalWithStdin with two code blocks: the first is the C++ program, the second is a text block with the stdin input.

```c
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;

  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += i;
    cout << "i=" << i << " sum=" << sum << endl;
  }
  cout << "Sum 1 to " << n << " = " << sum << endl;
  return 0;
}
```
``` text +stdin
10
```
@JSCPP.evalWithStdin

The +stdin label makes the input block visible and editable. Students can change the input values and re-run the program.


What JSCPP Supports

JSCPP implements a significant subset of C++:

  • Primitive types: int, float, double, char, bool, long
  • Control flow: if/else, for, while, do-while, switch
  • Functions (including recursion), pointers, references
  • Arrays and basic structs
  • cin / cout with << and >> operators
  • string basics (#include <string>)
  • Basic #include <iostream> and <cmath>

Limitations: JSCPP does not support the full C++ standard library, templates, or advanced STL features. It is best suited for introductory C++ courses covering algorithms, control flow, functions, and basic data structures.


Full Template Demo


Use Cases

Introductory programming — Teach C++ fundamentals — variables, loops, functions — without requiring students to install a compiler. The barrier to first code execution is zero.

Algorithm exercises — Sorting, searching, recursion, dynamic programming. Students write, test, and debug directly in the course material.

stdin/stdout programs — Many competitive programming problems use stdin/stdout. The @JSCPP.evalWithStdin macro lets students run typical contest-style programs with sample inputs.

Quizzes and exercises — Combine JSCPP code blocks with LiaScript’s quiz features. Ask students to complete a function, run it against a test case, and check the output.


Technical Facts

Runs in browserYes — JavaScript interpreter
Server requiredNo
Language versionC++ subset (no full STL or templates)
stdin supportYes — @JSCPP.evalWithStdin
Error messagesYes — with line number
Based onJSCPP by Felix Hao
LicenseMIT (implied)
MaintainedStable (version 0.3.1)

Try It

Try in LiaScript Open in LiveEditor View on GitHub
  • CodeRunner — server-side execution for full C++, Java, Python, and 20+ languages
  • WebDev — HTML, CSS, and JavaScript directly in the browser
  • Pyodide — full Python in the browser via WebAssembly
  • BiwaScheme — functional programming with Scheme in the browser

Related Posts

BiwaScheme for LiaScript: Functional Programming with Scheme in the Browser

Use the BiwaScheme template to run Scheme programs in your LiaScript courses — a complete Scheme interpreter in the browser, with an optional interactive REPL terminal.

Read More

Curiosity-Prolog for LiaScript: Lightweight Logic Programming in the Browser

Use the Curiosity-Prolog template to add a simple Prolog interpreter to your LiaScript courses — a lightweight alternative for introductory logic programming exercises.

Read More

DigiSim for LiaScript: Interactive Digital Circuit Simulation

Simulate digital logic circuits — from simple gates to D-latches and priority encoders — directly in LiaScript using the DigiSim template. Define circuits in JSON or JavaScript DSL.

Read More