visual-studio Visual Studio 中的 C++ 片段支持吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2789079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++ snippet support in visual studio?
提问by Jeremy Bell
I'm writing code in native C++ (not C++/CLR). I know that there is no built-in support for C++ with regards to the snippet manager and snipper picker interfaces, however I found a utility called "snippy" which supposedly can generate C++ snippets. Here is a c++ snippet that the program generated:
我正在用本机 C++(不是 C++/CLR)编写代码。我知道在代码段管理器和 snipper 选择器接口方面没有对 C++ 的内置支持,但是我发现了一个名为“snippy”的实用程序,据说可以生成 C++ 代码段。这是程序生成的 C++ 片段:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MySnippet</Title>
<Shortcut>MySnippet</Shortcut>
<Description>Just a test snippet</Description>
<Author>Me</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>literal1</ID>
<ToolTip>just a placeholder</ToolTip>
<Default>
</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="cpp"><![CDATA[cout << "$literal1$" << std::endl;]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
If there is support in visual C++, even in a limited capacity, for C++ snippets, how do I add them to my environment, and what are the limitations? All I need is support for basic expansion snippets that I can invoke by typing a shortcut and hitting tab, and which supports basic literals that I can tab through (basically, if it supports the above snippet, I'm good). If this can't be done, are there any free add-ons or extensions to visual studio that support snippets for C++? I'm using both visual studio 2010 and 2008, but I mostly write code in 2010 right now.
如果 Visual C++ 支持 C++ 片段,即使容量有限,我如何将它们添加到我的环境中,有哪些限制?我所需要的只是对基本扩展片段的支持,我可以通过键入快捷方式并点击 Tab 来调用这些片段,并且它支持我可以通过 Tab 键浏览的基本文字(基本上,如果它支持上面的片段,我很好)。如果无法做到这一点,是否有任何免费的附加组件或扩展可以支持 C++ 的代码片段?我同时使用 Visual Studio 2010 和 2008,但我现在主要在 2010 年编写代码。
采纳答案by sean e
Visual Assisthas a snippets featurethat is not quite the same as the IDE Snippets feature. It has its pros and cons, but does work in C++.
视觉协助有Snippets特点是不太一样的IDE片段的功能。它有其优点和缺点,但在 C++ 中确实有效。
回答by Matthew Manela
Visual Studio 2012 now includes snippet functionality for C++.
Visual Studio 2012 现在包括 C++ 的代码片段功能。
回答by TheHob78
回答by Nick Meyer
You want to download and install the Microsoft Visual Studio 2005 IDE Enhancements, which provides code snippet functionality for C++. The snippet support for C++ is not as robust as it is for the other languages, in my experience.
您想要下载并安装Microsoft Visual Studio 2005 IDE Enhancements,它为 C++ 提供代码片段功能。根据我的经验,对 C++ 的代码片段支持不如其他语言那么强大。
Source is here.
来源在这里。
回答by nobs
I'm using macros for codesnippet functionality. It's only a compromise but better then nothing
我正在使用宏来实现代码片段功能。这只是妥协,但总比没有好
for example pressing ++n -> adds comment line // myname [DATE]:
例如按 ++n -> 添加注释行 // myname [DATE]:

