1. 程式人生 > >Visual Studio 配置模板,快速定製初始頁面內容

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>