Home » Developer Tools » C++ Formatter
Paste C++ code and get clean, readable formatting in seconds, right in your browser.
Last updated 13 November 2026
This formatter changes whitespace only. It never compiles, runs, validates, adds, removes, or renames code tokens.
Messy C++ code with collapsed indentation is hard to read, review and debug. The C++ Formatter fixes indentation, line breaks and spacing so your code is easy to follow again.
Everything runs in your browser, so your code is never uploaded to a server. Paste your code, format it, and copy the result straight into your project.
This C++ formatter takes C++ code that is hard to read and lays it out again with clean indentation, line breaks and spacing. It changes whitespace only, so the code still does exactly what it did before, only now a person can follow it. It runs entirely in your browser, so nothing you paste is sent to a server.
It fixes the layout in three ways. It sets the indent of each line from the depth of the braces around it, so nested blocks step in one level at a time. It puts each statement on its own line, so you can read the code from top to bottom. And it sets the spacing around operators and after commas. For example, int*p becomes int * p and a=1+2 becomes a = 1 + 2.
It is a brace depth formatter, not a full C++ parser, and the page is honest about that. It never compiles, runs or validates your code, and it never adds, removes, renames or reorders a code token. Strings, character literals and comments are copied exactly, even when they look like code. A brace inside a string, such as printf("a{b}c"), stays exactly where it is, and a template type such as std::map<std::string, int> stays on one line.
The Load Sample button loads a small program as one line of 119 characters. Press Format and the same code comes back as 9 lines and 165 characters, with each block indented one level deeper than the one around it. The input and output are below, exactly as the tool produces them.
Input, 119 characters:
#include <vector>
int main(){std::vector<int> scores;int count=scores.size();if(count>=0){count=count+1;}return count;}
Output, 165 characters, 9 lines:
#include <vector>
int main() {
std::vector<int> scores;
int count = scores.size();
if (count >= 0) {
count = count + 1;
}
return count;
}
The output is longer than the input because indentation and line breaks are added back. That is the point: the extra characters are the structure made visible.
A second example is the one that used to split across lines. The input below is 60 characters:
int main(){std::map<std::string,int> m; m["a"]=1; return 0;}
The output is 78 characters on 5 lines, and the template type stays on one line:
int main() {
std::map<std::string, int> m;
m["a"] = 1;
return 0;
}
A nested template works the same way. The input below is 74 characters:
int main(){std::unordered_map<std::string, std::vector<int>> m; return 0;}
The output is 85 characters on 4 lines:
int main() {
std::unordered_map<std::string, std::vector<int>> m;
return 0;
}
Use the indent size box above the input to pick 2 or 4 spaces per level. Four spaces is the default, and it matches the LLVM style, which uses 4 spaces. Two spaces matches the Google style, which uses 2 spaces. Pick the size your project already uses, so the formatted code fits in with the rest of your files. Changing the size formats your code again if you already have an output. Tabs and 8 spaces are not offered.
Clang Format is a full C++ formatter. It enforces a named style such as LLVM or Google across a whole project, it reads a .clang-format file from your project, and it can check code as part of a build. Use it when a team needs one style enforced everywhere. This tool does one smaller job with no setup: open the page, paste code, press Format, and copy the result. There is nothing to install, no project to configure, and no account to create. Use this page when you need to read a snippet from a chat message, a forum answer, or a pasted file, and use Clang Format when you need to enforce a team style across a whole codebase.
If you want to try Clang Format on your own machine, install it and run it on a file with this command:
clang-format -i main.cpp
The -i flag edits the file in place. A .clang-format file in your project folder tells it which style to use, so every file in the project gets the same layout. You can also use Clang Format inside Visual Studio Code with the Clang Format extension, which formats the file each time you save it.
This tool is deliberately narrow, and it is honest about its limits. It never compiles, runs or validates your code, so it cannot tell you whether your code is correct. It does not sort includes, it does not offer a choice of brace style, and it does not wrap long lines. An opening brace that starts on its own line is moved to the end of the previous line, so code written in Allman style comes back in K and R style. Pointer stars are spaced on both sides, so int *p and int* q both become int * p. There is no file upload, so paste your code into the input box, and there is no format as you type, so press Format when you are ready. If you need a full style checker, use your IDE formatter or Clang Format, which enforces a complete style guide and reports errors. Use this tool for the quick job: take messy code and make it readable in seconds.
Format code before you read it, not after you have already struggled through it. Paste in a snippet from a chat message or a forum answer before you try to follow it. Format a file you are about to review, so the structure is clear before you judge the logic. Clean up code before you share it with a teammate, so the other person reads the idea and not the mess. In each case the job takes seconds, and the code you get back is the same code you put in, only laid out so a person can read it.
Yes, it is completely free with no sign up.
No. It changes whitespace only, meaning indentation, line breaks and spacing. It never adds, removes, renames or reorders code tokens, and it never compiles or runs your code.
No. Text inside string literals, character literals and comments is left untouched, even when it looks like code.
No. It never compiles, runs or validates code, so it cannot tell you whether your code is correct. It only makes the layout readable.
No. All formatting happens in your browser on your own device, so your code never leaves your computer.
Template brackets are kept with their type names, and namespace and class blocks are indented by brace depth, so generic code stays readable.
Yes. Paste the header code into the input box and press Format. The formatter treats header code the same way as any other C++ code, so class declarations, templates and inline functions all get the same clean layout. There is no file upload, so copy the header contents and paste them in.
No. A long line stays on one line, however long it is. If a line is too wide to read, split it into shorter lines before you paste it in, then press Format.
No. Include lines stay in the order you pasted them, and the formatter never adds, removes or reorders them. Preprocessor lines are copied exactly as written, at the start of the line.
Clang Format is a full C++ formatter that enforces a named style such as LLVM or Google, and it can check and fix code across a whole project. This tool is a small whitespace formatter that only fixes indentation, spacing and line breaks in the code you paste. Use this tool for a quick cleanup of a snippet, and use Clang Format when you need one style enforced across a project.
If you also work with other languages, try the C Formatter for the same clean formatting.