如何更改默认的 C++ 模板文件? [英] How to change the default C++ template file?

查看:42
本文介绍了如何更改默认的 C++ 模板文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Visual Studio 2019,每当我创建一个新的 C++ 项目时,它都会为我提供一个包含以下代码的默认文件:

I'm using Visual Studio 2019, and whenever I create a new C++ project it gives me a default file with the following code:

// Template Test.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

int main()
{
    std::cout << "Hello World!\n"; 
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file

这是太多不必要的信息,需要一分钟才能将其更改为我真正想要的;

This is so much unnecessary information and it takes a minute to change it to what I really want;

// Template Test.cpp : This file contains the 'main' function. Program execution begins and ends there.


#include <iostream>

using namespace std;

int main() {
    cout << "Hello World!\n"; 
}

不需要太多时间,但是每次在 VS 19 中创建新的 C++ 控制台项目时我都必须这样做.

It doesn't take very much time, but I have to do it every time I create a new C++ console project in VS 19.

在我的电脑上快速搜索后,我在以下位置找到了一个名为Templates"的文件夹:

After doing a quick search on my computer I found a folder called 'Templates' at the following location:

C:\Users\yale\Documents\Visual Studio 2019\Templates

C:\Users\yale\Documents\Visual Studio 2019\Templates

这个文件的子目录会让我认为这是正确的地方,但我看到的文件夹都没有任何模板文件.

This file has subdirectories that would lead me to think it's the right place, but none of the folders have any template files as I can see.

如何使用 Visual Studio 2019 在 C++ 中修改不同项目的模板文件?

How can I modify the template files for different projects in C++ with Visual Studio 2019?

推荐答案

您可以通过两种方式进行选择.

There are two ways you can choose any of them.

使用导出模板向导:

Visual Studio 提供了可用于更新现有模板的导出模板向导:

Visual Studio provides an Export Template Wizard that can be used to update an existing template:

  • 从菜单栏中选择文件 > 新建 > 项目.
  • 选择要更新的模板并继续创建新项目的步骤.
  • 在 Visual Studio 中修改项目.例如,改变输出在项目中键入或添加一个新文件.
  • 在项目"菜单上,选择导出模板".导出模板向导打开.
  • 按照向导中的提示将模板导出为 .zip文件.
  • (可选)将 .zip 文件放在以下目录中:%USERPROFILE%\Documents\Visual Studio\Templates\ProjectTemplates 使其可用于选择.如果您没有选择选项自动将模板导入到 Visual Studio 中导出模板向导.
  • 删除旧模板 .zip 文件.

手动更新现有模板:

  • 找到包含模板的 .zip 文件.用户项目模板位于 %USERPROFILE%\Documents\Visual Studio\Templates\ProjectTemplates.
  • 解压 .zip 文件.
  • 修改或删除当前模板文件,或添加新文件到模板.
  • 打开、修改并保存 .vstemplate XML 文件以处理更新的行为或新文件.
  • 选择模板中的文件,然后右键单击或上下文菜单,然后选择发送到 > 压缩(zipped)文件夹.这您选择的文件将被压缩为 .zip 文件.
  • 将新的 .zip 文件与旧的 .zip 文件放在同一目录中.
  • 删除提取的模板文件和旧模板 .zip 文件.

此外,您还可以访问 源页面了解更多详情.

Also, you can visit the source page for more details.

这篇关于如何更改默认的 C++ 模板文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆