C++ text formater

Years ago, when working with Pascal, I had a 'text formatter' that would arrange my Pascal text file into clean, uniform, styled text layout.

Is there something like this available for C++?
There is an online formatter at http://www.tutorialspoint.com/online_c_formatter.htm
Many IDE's also have code formatting options.
Is there something like this available for C++?

Yes. For stuff that needs more help than my editor (Emacs) will fix automatically, clang-format is useful.
https://clang.llvm.org/docs/ClangFormat.html
Last edited on
visual studio has built in formatter.
Notepad ++ has one I think.

It takes about 10 min to write your own, tops. A really basic one just counts the brace pairs, destroys all leading white space on all lines, and puts it back based off the current brace count. So .. crudely

if '{' bc++ ...

and on each line
(for... x<bc << x++)
cout << ' '; //or tab, or 3 spaces, or whatever your preference is
cout << line << endl;

I had mine drop all { and } on a line with nothing else, to undo misaligned and 'textbook' format mess.



Topic archived. No new replies allowed.