C++ Formatting like Visual Studio C# formatting

半世苍凉 提交于 2019-12-06 17:25:50

问题


I like the way Visual Studio (2008) formats C# code; unfortunately it seems it doesn't behave in the same way when writing C++ code.

For example, when I write a code in this way:

class Test {
public:
    int x;
    Test() {this->x=20;}
    ~Test(){}
};

in C# (ok this is C++ but you can understand what I mean), this part:

Test() {this->x=20;}

Will become:

Test() { this->x=20; }

This is obviously a stupid example, but there are a lot of things where putting brackets in correct position, indenting code and other things with my own hands becomes boring.

I can obviously change editor if you suggest me a good one for C++ code, I would like to find something with these features:

  • Intellisense (like vs, at least similar)
  • Custom class coloring (in C=C# they are cyan, why are they black in C++?)
  • Wordwrap (possibly)
  • Documentation when you mouse over a method/variable
  • Auto formatting (when you close a bracket like "}" in C# you'll get everything well formatted)

Obviously I can find other features, but this is what is in my mind at the moment.

Thanks for any suggestion.


回答1:


I'm using AStyle extension for VS2012 and I'm happy with it.
It's free :)




回答2:


Select the code-text and press CTRL+K-F in Visual Studio - That's it :)




回答3:


If you look at the Tools->Options->Text Editor settings you can control some of what you want, but I don't think as much as you'd like. Instead of changing editors, if the code style is that important, why not run it through a pretty printer? Check out this thread for ideas.




回答4:


You'll struggle to find a much better editor than Visual Studio for writing c++ code. You will get used to it eventually. If you really cannot cope, then take a look at Visual Assist. It is a little pricey but it will beautify your code colours.




回答5:


SlickEdit is a highly configurable editor and offers tagging functionality (what VS calls "Intellisense") that blows VS and Visual Assist out of the water. Plus there's a cool preview window that shows you the definition for the thing under the cursor, which is lightning fast (and you can turn off if you want).

I use vim these days, though, which is even more highly configurable, and I'll never go back. It's a little trickier to get configured well, though.



来源:https://stackoverflow.com/questions/2608696/c-formatting-like-visual-studio-c-sharp-formatting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!