C++ Beautifier

Restore readable indentation in a C++ header or translation unit, with public and private labels pulled back to the class margin.

C++ source
Formatted C++
Runs locally in your browser

About the C++ Beautifier

C++ layout is decided by braces, but a handful of constructs need special care and this beautifier handles them explicitly. Access specifiers such as public:, protected: and private: are moved onto their own line and printed one level out from the members that follow, which is the convention nearly every C++ style guide shares. Qualified names like std::vector are left alone because the scanner only treats a colon as a label when the whole line up to it is a single access keyword.

Raw string literals written as R"delim(...)delim" are recognised and copied out verbatim, braces and all, so embedded shader source or SQL does not throw the depth counter off. Angle brackets in template parameter lists are ordinary characters here and are never spaced out, which avoids the classic mistake of turning vector<int> into something a compiler reads differently.

Preprocessor directives, include guards and #pragma lines are pinned to column zero. Constructor initialiser lists keep the shape you gave them because the colon inside them is not a label. Comments, both line and block, pass through with their text intact.

The pass is deliberately conservative: no expression is rewrapped and no operator spacing is invented. If you need real C++ formatting with column limits and pointer alignment, run clang-format locally. For a plain C file the C Beautifier uses the same engine without the class label rules.

How to use

  1. Paste a .cpp, .cc or .hpp file into the left pane, or press Sample for a small class with an initialiser list.
  2. Pick your Indent. Two spaces matches the Google and LLVM styles, four matches many game engines.
  3. Turn Split statements onto new lines off if the file already has the line breaks you want.
  4. Check the access labels landed where you expect, then Copy or Download the result.

Common questions

Does it handle templates and lambdas?
Yes. Template angle brackets are copied through untouched and a lambda body is indented from its braces like any other block.
Why is my constructor initialiser list still on one line?
Nothing is rewrapped. The beautifier changes leading whitespace and, when enabled, adds breaks at braces and top level semicolons. Wrapping a long initialiser list is left to you.
Is a raw string with braces inside it safe?
Yes. The R"(...)" form including a custom delimiter is scanned as one literal and its contents never affect indentation.
Can I run it on a whole header with include guards?
Yes. The guard directives print at column zero and the code between them indents from the braces as usual.