C/C++ Formatter

Format C and C++ functions, classes, headers, templates, and pasted snippets with consistent indentation, spacing, braces, and line breaks while preserving comments and program behavior.

C/C++ formatting styles

Select LLVM, Google, Chromium, Mozilla, WebKit, or GNU as the base style. The indent width accepts 1 to 16 spaces, and the column limit accepts 0 to 1000; use 0 for no line wrapping. Load a local source file, then copy or save the formatted result.

Code formatter FAQ

How do I format code on this page?

Paste code into the left editor or load a file, choose the options you need, and select Format. Review the result on the right, then copy or save it.

Why might the formatter report an error?

The input must match the selected language or syntax. Check incomplete statements, unmatched brackets or quotes, and a dialect or mode that does not match the input, then format again.

How does a code formatter work?

A code formatter reads language-aware tokens and nested structures, then rewrites indentation, spacing, and line breaks according to a consistent rule set. It does not compile or run the program, so formatting is not a correctness or security check.

Which settings are recommended for this language?

For Google-style C++, start with 2 spaces and an 80-column limit; 100 columns is also a practical team choice for wider screens. Choose LLVM, Google, Chromium, Mozilla, WebKit, or GNU style, then set the indent width and column limit.