tags:

views:

267

answers:

5

I've been using VS2005 and VS2008 now for a while, with C#. Without any additional tools I could hit ctrl k + d and the code would nicely reformat. Why doesn't C++ do this? It's the same Visual Studio after all. Is there a way to enable it?

A second part of this question is related, for those who've been using resharper with C#, is there a similar tool for C++?

+2  A: 

It's probably there, but mapped to a different keyboard shortcut. For example, on my VS2008 install Ctrl+K,D doesn't map to anything but Ctrl+E,D maps to the Edit|Advanced|Format Document command.

Scott Dorman
Running VS2008EE I can only see a Ctrl+K,F "Format Selection" command
GRB
+4  A: 
  1. You can use Ctrl-K+Ctrl-F for "format selection".

  2. Link

barism
A: 

For me it's always been select text, CTRL + K, F. It doesn't do as well as in Visual C# though; there are no customization options beside the most basic ones.

Dr_Asik
A: 

Ontopic: In VS2008 Express Format Selection is ALT+F8 and CTRL+K, CTRL+D is mapped to Format Document. It's probably the same in professional versions of VS2008.

Less ontopic: I tend to avoid source code formatters for C++ as I feel they generally often does more harm than good. Why? Codeformaters has to "read" the code and understand what the different code statements do. This is quite easy in e.g. Java where the syntax is straight forward. C++ is a very complex language. There's 10 ways to do just about anything. You can use macros, defines, typedefs and whatnot. Classes are usually defined/declared in two different files. This is also the reason that Intellisense seems to fail quite often - VS2008 fails parsing the code correctly. It's very hard for an IDE to know what all statements is and how to format them. Although it may work ok most of the time, you can be pretty sure that it will give bad results now and then. I'm guessing Microsoft didn't spend too much time customizing the code formatter for C++ as they realize that most C++-programmers do this by hand anyways. I rarely miss it, except when some co-worker of mine isn't following the company standard.

larsm
A: 

You can always use AStyle to format your code. Works great!

0A0D