Run C++ and C Code

Run C++ and C Code: One-Click Compile with GCC, G++, Clang (CPP Runner, Input Panel), a VS Code extension by Zovo

Free, no sign-in, works offline. Click Run on a .c or .cpp file. The extension compiles it with the gcc, g++, clang or clang++ already on your computer and runs the program in the terminal, where scanf and cin work. Errors go to the Problems panel at the right line. An Input panel keeps test cases and shows pass or fail with a diff.

Install in VS CodeOpen the Marketplace page

Free, MIT license. Needs VS Code 1.90.0 or newer. Extension ID zovo.zovo-run-cpp, version 0.2.2.

A C++ file with the Run button in the editor title, and the program running in the terminal: typed input, then the exit code, run time and peak memory

Questions people ask

Is Run C++ and C Code free?

Yes. Run C++ and C Code is free and MIT licensed.

How do I install Run C++ and C Code?

Click "Install in VS Code" above, or search for zovo.zovo-run-cpp in the Extensions view.

Why this one

The two most installed C/C++ run extensions on the Marketplace are good and popular. These are requests and bug reports from their issue trackers that this extension handles, each checked in a real VS Code run (see Tested):

Request or reportIssueHere
Compile flags for one source file, and the optimization levelvscode-c-cpp-runner #135, #147, #183 (open)A // run: -O2 -DFOO=7 line applies to that file only and comes after the defaults, so -O2 wins over -O0.
Program arguments with spaces: "Hello World" became 2 argumentsvscode-c-cpp-runner #157 (open)// args: "Hello World" 2 gives argc 3 and argv[1] = Hello World.
Chinese folder names garbled in the Problems panel, so the error could not be clickedc-cpp-compile-run #377, #402The compiler output is read as UTF-8 and every path is matched to the file that was compiled. A compile error in my code/ü/你好.cpp shows in Problems on the right file and line.
*.cpp wildcard fails with MSYS2 gcc on large projectsvscode-c-cpp-runner #176 (open)Folder builds list each file by name. No wildcard, no shell.
Spaces or & in a path break the buildvscode-c-cpp-runner #121, #76, c-cpp-compile-run #71Every argument goes to the compiler and to your program as a separate item, never through a shell.
Workspace settings overwrittenvscode-c-cpp-runner #159This extension never writes your settings files. Debug adds one entry to launch.json, and only when you press Debug.
One button to compile and runvscode-c-cpp-runner #170 (open)Run builds and runs. Build only is in the "..." menu.

Run a file

  1. Open a .c, .cpp, .cc or .cxx file.
  2. Click the Run button (top right), press Ctrl+Alt+Enter (Cmd+Alt+Enter on Mac), or right-click and pick Run C/C++ File.
  3. The program runs in a terminal named "Run: file.cpp". Type its input there. At the end you see the exit code, the run time and the peak memory.

The program runs with the terminal as its console, so prompts without a newline show up before cin waits, as in any shell. While it runs, the Run button turns into Stop.

The keybinding is not used by VS Code or by the two most installed runners (they use F5 to F8, Ctrl+6, Ctrl+Alt+R/B/D/A). Change it in Keyboard Shortcuts: "Run C++: Run C/C++ File".

Input & Tests panel

Open it with Run C++: Run with Input & Test Cases, or from the Run C++ tab in the bottom panel.

The Input & Tests panel in the light theme with input, output, run time, peak memory and a failed test case with a line diff

Flags and arguments per file

// run: -O2 -lm util.c
// args: "Hello World" 3

run: adds compiler flags (and extra source files) for this file. args: sets the program arguments; quotes keep spaces together. Both are read from the first 40 lines. The defaults are -std=c++20 -Wall -Wextra -g -O0 for C++ and -std=c17 -Wall -Wextra -g -O0 for C (settings zovoRun.cppFlags, zovoRun.cFlags). C programs are linked with -lm. If the compiler is too old for C++20 or C17, the build steps down to the newest standard it knows and says so.

Errors and warnings

Compiler errors and warnings from gcc and clang go to the Problems panel with file, line and column, and notes are attached to their error. Linker errors (for example undefined reference to sqrt) show on the file with a hint (-lm, or build the whole folder). The full compiler output is in the "Run C++ and C" output channel.

Large output, endless loops, crashes

Compilers

gcc, g++, clang and clang++ are found on PATH. On Windows the extension also looks in C:\msys64\ucrt64\bin, C:\msys64\mingw64\bin, C:\msys64\clang64\bin, C:\MinGW\bin, C:\mingw64\bin, the WinLibs winget folder, TDM-GCC, Chocolatey MinGW, Scoop and C:\Program Files\LLVM\bin. Homebrew names like g++-14 are found too. Run C++: Pick Compiler lists what was found, with versions.

When there is no compiler, a setup page shows the official steps for your system (Xcode Command Line Tools, MSYS2 or WinLibs, your Linux package manager) and a Check again button. The extension never downloads a compiler.

Debug

Run C++: Debug C/C++ File builds with -g and starts the debugger with CodeLLDB or the C/C++ extension (gdb or lldb), whichever is installed. It adds one entry named "Debug file.cpp (Run C++)" to .vscode/launch.json (turn off with zovoRun.writeLaunchJson).

Built programs

Programs go to .zovo-run/bin/ in the workspace folder, with a .gitignore inside so git skips them, or to the system temp folder (zovoRun.outputFolder). A file is built again only when it, a header next to it, or its flags changed. Run C++: Delete Built Programs removes them.

Related tools: Open Built Program in Hex Viewer (with the free Zovo Hex Viewer), and Open Linker Map File for builds with // run: -Wl,-Map=app.map (with the free Zovo Linker Map Viewer).

Stress test and benchmark

In the Input & Tests panel under "Stress test and benchmark":

Privacy

No network, no telemetry, no account. The extension starts only your compiler and your program. The rating question and the support links open a web page only when you click them.

Settings

SettingDefaultWhat it does
zovoRun.cppCompiler, zovoRun.cCompilerautomaticName on PATH or full path
zovoRun.preferredCompilerautoTry gcc or clang first
zovoRun.cppFlags, zovoRun.cFlags, zovoRun.linkFlagssee aboveCompiler and linker flags
zovoRun.outputFolderworkspace.zovo-run/bin or the temp folder
zovoRun.timeLimitSeconds10Limit for Input panel runs and test cases
zovoRun.compareModetrimHow test output is compared
zovoRun.focusTerminaltrueFocus the terminal so you can type input
zovoRun.askForRatingtrueOne rating question after 2 good runs in 2 sessions
zovoRun.showSupportLinkstrueRate, More free tools and Sponsor links in the panel

License

MIT

Guides

Install Run C++ and C Code

Click the button to open VS Code and install it, or press Ctrl+P (Cmd+P on macOS) in VS Code and run ext install zovo.zovo-run-cpp.

Free, MIT license. Needs VS Code 1.90.0 or newer. Extension ID zovo.zovo-run-cpp, version 0.2.2.

Source code and issues are on GitHub.

All our VS Code extensions

Zovo Pro and support

Zovo Pro: USD 19 once, every Zovo viewer. It turns on the Pro tools in this extension and in the other Zovo extensions you use. The free features stay free.

After a card payment your license key shows on the next page. Paste it with the command "Zovo Pro: Enter a key".

You can also support the work with no Pro:

Need your format supported?

Open a format request with a sample file, and I reply there whether it can be done. For USD 299 once, through this GitHub Sponsors tier, I add your file format or a missing feature to this extension, with tests, within 7 days.