美文网首页
VS中添加自定义代码片段

VS中添加自定义代码片段

作者: 写一行代码 | 来源:发表于2020-08-30 20:04 被阅读0次

工具->代码片段管理器
选中Visual C++,打开位置对应的路径,新建两个文件,名字分别为#1.snippet和#2.snippet,然后重启VS,在一个.c结尾的文件中输入#1或者在.cpp结尾的文件中输入#2,可以实现自动生成。

#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>
#include <math.h>
#include <time.h>
#include <Windows.h>

int main(void)
{
    $selected$$end$
    system("pause");
    return EXIT_SUCCESS;
}
                    ]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

#2.snippet

<?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>

相关文章

网友评论

      本文标题:VS中添加自定义代码片段

      本文链接:https://www.haomeiwen.com/subject/howesktx.html