Question

I'm looking for a tool that works on Windows to reformat some C++ code in my codebase. Essentially, I've got some code I wrote a while ago that I'd like to use, but it doesn't match the style I'm using in a more recent project.

What's the best way to reformat C++ code in a standard manner?

Billy3

Was it helpful?

Solution

In Visual Studio: Edit / Advanced / Format Document

The format applied to the document will match the settings in: Tools / Options / Text Editor / C/C++

Visual Studio might not support all the formatting options you want applied to your document, in which case you'll need a separate tool (such as Paul Betts is suggesting) to format the way you want.

OTHER TIPS

GNU Indent should get you most of the way there

Astyle is one of the more popular tools.

Edit: I don't know why I didn't think about it when I first posted this, but you can also use Vim. The = command will reformat your code according to your indentexpr and cinoptions.

GC Great Code has been an old standby for me. It's quite configurable.

http://sourceforge.net/projects/gcgreatcode/

Visual Studio can. And most IDEs can.

I have also used AStyle in the past. I used this GUI for it to make it a bit easier (I think--it's been a while): Artistic Style for Windows: http://jimp03.zxq.net/

Eclipse/CDT can indent your code very well...

  • Its configurable.
  • You can also share the settings within your team/group/organization.

P.S. I am writing something about that in my Book Post comment if you have some direct questions. :-)

use AStyle ( inbuilt in codeblocks )

Step 1 : Select your code
Step 2 : Click on Plugins->Source Code Format (AStyle )

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top