Visual Studio 2010 C++代码格式化程序
我是在 Visual Studio 中编写 C++ 程序的新手。当我在 VS 中编写 C# 程序时,代码格式化程序会将如下所示的代码更改
for(int i= 0; i<(n+ m) ; i++){
}
为
for(int i = 0; i < (n + m); i++)
{
}
更易于阅读的方式。当我用 C++ 编写同样的东西时,什么也没有发生。我尝试选择文本并按 Ctrl+E、F,但这不起作用。有没有办法改进 Visual Studio 中的 C++ 代码格式化程序?
I'm new to coding C++ programs in Visual Studio. When I am coding C# programs in VS, code formatter changes code that looked like this
for(int i= 0; i<(n+ m) ; i++){
}
into
for(int i = 0; i < (n + m); i++)
{
}
which is way easier to read. When I write the same thing in C++, nothing happens. I tried to select the text and press Ctrl+E, F, but that didn't work. Is there a way to improve the C++ code formatter in visual studio?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Visual Studio 无法格式化 C++ 代码。也许有 VS 扩展。我找了好久,一直没找到合适的免费的。
GreatCode 是一个非常好的、免费但不太容易使用的代码格式化程序。它是一个命令行工具。
您可以将其配置为“外部工具”:
在硬盘上解压 GreatCode 后,只需转到“工具”->“外部工具”->“添加”并插入以下设置...
每当您调用该工具时,实际打开的文件都会被格式化。
您可以在 gc.cfg 中根据需要配置 GreatCode。我尝试了很多选择,有些很简单,有些很复杂。
如果您想要类似微软的外观,只需使用我的设置作为模板并自行微调即可:
祝您好运!
Visual Studio can't format C++-Code. Maybe there is a VS extension. I searched a long time, but never found a suitable one for free.
A very good, free, but not easy to use code formatter is GreatCode. Its a command line tool.
You can configure it as "External Tool":
After unpacking GreatCode on your HD just go Tools->External Tools->Add and insert the following settings...
Whenever you call that Tool, the actual opened file is being formatted.
You can configure GreatCode as you like in the gc.cfg. I tried many options, some are easy, some are complex.
If you want a Microsoft-like looking, just use my settings as a template and fine tune yourself:
Good luck!
除了格式化工具本身之外,我使用与 DirkMausF 完全相同的方法。我建议您使用艺术风格格式化程序:
http://astyle.sourceforge.net/
它有很好的文档记录并且附带了很多内容预定义的格式样式,因此非常易于使用。
I use exactly the same approach as DirkMausF except the formatting tool itself. I would suggest you to use Artistic Style formatter:
http://astyle.sourceforge.net/
It is well documented and comes with a lot of predefined formatting styles so it is very easy to use.
如果您有现金可花,您可能需要查看 Visual Assist。另请参阅此问题。
If you have cash to spend, you might want to look in to Visual Assist. See also, this question.
很长一段时间,我都是在 Netbeans 中编写所有 C++ 代码,并在 Visual Studio 中编译它。 Netbeans 可以完美地格式化代码(使用 ALT+SHIFT+F),并且有许多格式化选项。
For a long time, I was writing all the C++ code in Netbeans and I was compiling it in Visual Studio. Netbeans is formatting code perfectly (with ALT+SHIFT+F) and there are many formatting options.