C++
Object-oriented extension of C with modern features
Overview
C++ extends C with object-oriented programming, templates, and modern features. It's used for game development, high-performance applications, and systems programming.
Language Aliases
run cpp "#include <iostream>
int main() { std::cout << "Hello" << std::endl; return 0; }"
run c++ "#include <iostream>
int main() { std::cout << "Hello" << std::endl; return 0; }"
run g++ "#include <iostream>
int main() { std::cout << "Hello" << std::endl; return 0; }"
Hello
Hello
Hello
Basic Usage
run cpp "#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}"
Hello, World!
run cpp "#include <iostream>
int main() {
int x = 42;
std::cout << "Value: " << x << std::endl;
return 0;
}"
Value: 42
Piping Code to run
C++ works well with both echo and cat for piping code. Use whichever is more convenient:
echo '#include <iostream>
int main() { std::cout << "Hello" << std::endl; return 0; }' | run cpp
cat <<'EOF' | run cpp
#include <iostream>
int main() {
std::cout << "Hello " << 42 << std::endl;
return 0;
}
EOF
Step-by-step in REPL Mode
For step-by-step execution with persistent state, enter REPL mode once, then type commands interactively:
$ run cpp
run universal REPL. Type :help for commands.
cpp>>> #include <iostream>
cpp>>> int square(int x) { return x * x; }
cpp>>> std::cout << square(7) << std::endl;
49
cpp>>>
REPL Behavior - Stateful
C++'s REPL is STATEFUL within a single interactive session:
• Start REPL with 'run cpp'
• Includes, functions, and variables persist at the cpp>>> prompt
• Each command builds on previous definitions in that session
• Separate 'run cpp "code"' invocations are independent compilations
Common Issues & Solutions
Here are solutions to common problems when working with C++ in run:
int square(int x){ return x*x; }
std::cout << square(7) << std::endl;
error: use of undeclared identifier 'std'
#include <iostream>
int square(int x) { return x * x; }
std::cout << square(7) << std::endl;
49
cat <<'EOF' | run cpp
#include <iostream>
int square(int x) { return x * x; }
int main() {
std::cout << square(7) << std::endl;
return 0;
}
EOF
49