Format
Rewrites your C++ with consistent braces, spacing, and indentation using clang-format. Turns cramped or messy code into clean, readable source.
class A{int x;};Afterclass A {
int x;
};Paste cramped or messy C++ and get it back with consistent braces, spacing, and indentation. The formatter is clang-format, running in your browser, so your code stays on your device.
Format uses clang-format. The style and indent options apply to Format.
C++ gives you a lot of freedom over spacing and brace placement, and templates and long type names make it easy for code to get cramped. A formatter, also called a beautifier, rewrites the source with one consistent set of rules: braces in the same place, even indentation, and consistent spacing. This tool uses clang-format, a widely used C++ formatter, and changes only the layout, never what the program does.
Rewrites your C++ with consistent braces, spacing, and indentation using clang-format. Turns cramped or messy code into clean, readable source.
class A{int x;};Afterclass A {
int x;
};Pick the base style clang-format follows: Google, LLVM, Mozilla, WebKit, and more. Each sets brace placement, spacing, and other rules to match a well-known C++ style.
Google, LLVM, Mozilla...AfterYour chosen house styleChoose 2 or 4 spaces for each level of nesting, so the formatted C++ matches the style used in the rest of your project.
2 spaces or 4 spacesAfterYour choice per levelA formatter helps whenever C++ source is hard to read or needs to match a shared style. These are the cases that come up most:
Once your C++ is formatted, these references explain the language and the formatter behind this tool:
This tool runs clang-format, the standard formatter for C++, compiled to run in your browser. The same styles work on your machine:
| To | Use |
|---|---|
| Format a file in place | clang-format -i main.cpp |
| Pick a base style | clang-format -i --style=Google main.cpp |
| Save a style for the project | clang-format --style=LLVM --dump-config > .clang-format |
| Format on save | The C/C++ extension in VS Code and CLion both use a .clang-format file if one is present |
When a .clang-format file is in your project folder, clang-format uses it automatically, so everyone on the team gets the same layout.
If you work across languages, these formatters run the same way, right in your browser: