【发布时间】:2019-04-09 15:48:56
【问题描述】:
我使用的是 Visual Studio 2019,每当我创建一个新的 C++ 项目时,它都会为我提供一个包含以下代码的默认文件:
// 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
这是太多不必要的信息,需要一分钟才能将其更改为我真正想要的;
// 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++ 控制台项目时都必须这样做。
在我的电脑上快速搜索后,我在以下位置找到了一个名为“模板”的文件夹:
C:\Users\yale\Documents\Visual Studio 2019\Templates
这个文件有子目录,让我觉得它是正确的地方,但没有一个文件夹有任何模板文件,我可以看到。
如何使用 Visual Studio 2019 修改 C++ 中不同项目的模板文件?
【问题讨论】:
-
你真的应该避免使用
using namespace std;,坚持使用std::name_of thing,或者至少使用using std::name_of_thing;,然后只使用name_of_thing。您也可以创建一个空项目,因为不需要#include <iostream> int main() {}的所有内容。 -
访问this页面可能会对您有所帮助。
-
我建议设置一个轻量级 Cmake 项目基线,它会让您习惯 cmake,并允许您为每个要开发的新项目复制基线。
-
@LionKing 谢谢,这解决了我的问题!
标签: c++ visual-studio visual-studio-2019 file-templates