Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a utility to indent C++ programs [closed]

I am trying to use "indent" program to indent C++ programs. But it does not seem to work fine. It is messing up the indentation much more.

It is a Class file. Can you please suggest the right options for it or another program that works?

Thanks

like image 271
user855 Avatar asked Nov 28 '09 21:11

user855


People also ask

Is there indentation in C?

1 The indent Program. The indent program can be used to make code easier to read. It can also convert from one style of writing C to another. indent understands a substantial amount about the syntax of C, but it also attempts to cope with incomplete and misformed syntax.

How do you indent an entire block of code?

You (these are the default settings I believe) can select a block of code and press the Tab key. This will indent the entire block. So for indenting a whole file: Ctrl + A , then Tab .

Do tabs matter in C?

No. The emitted binary doesn't change based on what spacing you use in your program. The amount of space the source file takes up does change though. spaces and tabs are each one character, so using 1 tab vs 4 spaces takes up different amounts of memory.

How do you indent everything or code?

I want to indent a specific section of code in Visual Studio Code: Select the lines you want to indent, and. use Ctrl + ] to indent them.


4 Answers

Try Artistic Style:

Artistic Style is a source code indenter, formatter, and beautifier for the C, C++, C# and Java programming languages.

like image 88
Andrew Hare Avatar answered Oct 29 '22 16:10

Andrew Hare


in visual studio, CTRL+a, CTRL+k, CTRL+f will auto-indent the entire file you're working in.

like image 32
Rantaak Avatar answered Oct 29 '22 18:10

Rantaak


Another tool for automated formatting of C++ code is clang-format.

like image 45
Philipp Avatar answered Oct 29 '22 16:10

Philipp


Many editors like Vim and Emacs have a feature that reindents code according to its built-in indentation standard.

In Vim, you can type = with any motion. (Like =% at any block delimiter or S-v to select a region and then = to reformat.) The gq command can be used to reformat comments and other text.

In Emacs, you can type M-x indent-region after selecting a region. (Such as with M-< and M->.) You can also reformat comments with M-x fill-paragraph.

like image 27
greyfade Avatar answered Oct 29 '22 16:10

greyfade