C / C++ Formatter
Format and validate C/C++ code online for free with clang-format, right in your browser.
Local browser processing
No sign-up required
Powered by clang-format
LanguageFor C and C++ code
C++main.cpp
Dialect
Style
Indent
Line width
InputEditable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
OutputC++ valid27 lines · 595 B
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
class Person {
public:
Person(std::string name, int age) : name_(name), age_(age) {}
std::string getName() const { return name_; }
int getAge() const { return age_; }
bool operator<(const Person& other) const { return age_ < other.age_; }
private:
std::string name_;
int age_;
};
int main() {
std::vector<Person> people = {{"Alice", 30}, {"Bob", 25}, {"Carol", 35}};
std::sort(people.begin(), people.end());
for (const auto& p : people) {
std::cout << p.getName() << ": " << p.getAge() << std::endl;
}
return 0;
}
UTF-8 · 4 spaces · Google · clang-formatLocal processing · Ready
How It WorksC / C++
Overview
This C/C++ formatter cleans up code with inconsistent indentation or mixed styles into a standard format, powered by a WebAssembly build of clang-format. It supports seven presets — Google, LLVM, Chromium, Mozilla, WebKit, Microsoft, and GNU — plus custom indent width and line length. Everything runs locally in your browser; your code never leaves your device.
Use Cases
Format C/C++ code pasted from docs or generated by AIUnify a team's code style (Google/LLVM)Clean up legacy code with inconsistent indentationValidate whether code syntax is correct
Steps
123
Paste or uploadChoose a styleGet the result