Visual Studio 配置模板,快速定制初始页面内容

在Visual Studio开发C/C++,特别是学习时期,每一个页面总会要输入相同的内容。最近经高手指点,知道#1 弹出C的模板内容,#2弹出C++的模板内容,是如何实现的,下面简单记录一下。

0.创建#1.snippet和#2.snippet(具体内容见下方),放入某一个目录。
1. 打开Visual Studio,在菜单栏选择Tools->Code Snippet Manager…
2. 在弹出的页面中,Language选择C++,在下面类似资源管理器的部分中选中Visual C++,点击Add,选中,#1.snippet和#2.snippet的文件夹。
3. 测试。新建页面,输入 #1然后点击tab。ok,生成,其内容如下:

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{



    system("pause");
    return EXIT_SUCCESS;
}
//#1.snippet
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>#1</Title>
            <Shortcut>#1</Shortcut>
            <Description>c语言main函数</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
                <SnippetType>SurroundsWith</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>expression</ID>
                    <ToolTip>要计算的表达式</ToolTip>
                    <Default>true</Default>
                </Literal>
            </Declarations>
            <Code Language="cpp"><![CDATA[#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { $selected$$end$ system("pause"); return EXIT_SUCCESS; }]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>#2</Title>
            <Shortcut>#2</Shortcut>
            <Description>c++语言main函数</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
                <SnippetType>SurroundsWith</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>expression</ID>
                    <ToolTip>要计算的表达式</ToolTip>
                    <Default>true</Default>
                </Literal>
            </Declarations>
            <Code Language="cpp"><![CDATA[#define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; int main() { $selected$$end$ system("pause"); return EXIT_SUCCESS; }]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
    原文作者:码农000
    原文地址: https://blog.csdn.net/guchuanhang/article/details/70939682
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞