什么是快捷代码段:
例如: 只需要输入mst后按一下TAB就会自动生成代码memset(str, 0, sizeof(str));,只需要输入Pow就可以自动生成一个快速幂函数等等,非常方便快捷,一定程度提高了编写代码的效率
Visual Studio 设置自定义代码段方法:
①新建文件XXX.snippet,其中的"XXX"就是上述的" ow"、"mst",也就是代码段的简写
②复制以下代码(不知道VS不同版本是否相同,如果不同可以去工具-快捷代码段里面找现成的,然后再修改)
- <?xml version="1.0" encoding="utf-8"?>
- <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
- <CodeSnippet Format="1.0.0">
- <Header>
- <Title>Res</Title>
- <Shortcut>Res</Shortcut>
- <Description>结构体代码段</Description>
- <Author>Bycds</Author>
- <SnippetTypes>
- <SnippetType>Expansion</SnippetType>
- <SnippetType>SurroundsWith</SnippetType>
- </SnippetTypes>
- </Header>
- <Snippet>
- <Declarations>
- <Literal>
- <ID>index</ID>
- <Default>i</Default>
- <ToolTip>索引</ToolTip>
- </Literal>
- <Literal>
- <ID>max</ID>
- <Default>length</Default>
- <ToolTip>最大长度</ToolTip>
- </Literal>
- </Declarations>
- <Code Language="cpp">
- <![CDATA[typedef struct Res //在这个地方输入你要快捷生成的代码
- {
- int x, y;
- bool operator < (const Res &b) const
- {
- if(x<b.x)
- return 1;
- return 0;
- }
- }Res;
- Res s[200005];]]>
- </Code>
- </Snippet>
- </CodeSnippet>
- </CodeSnippets>
复制代码 ③在CODE位置输入你需要得代码段,注意修改Title要和你的文件名一致
④新增自己的代码段


之后选择你创建的.snippet文件即可
⑤重启VS,搞定

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |