有什么方法可以使VSCode在我创建的每个新文件中添加以下代码?或仅带有.cpp扩展名的
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main() {
return 0;
}
这将使生活更轻松,因为每次创建新文件时都不需要CTRL + C和V
答案 0 :(得分:0)
恐怕没有扩展名是不可能的,尽管您可以编写一个片段来简化工作。
要创建或编辑自己的代码段,请在“文件”>“首选项”(在macOS上为“代码”>“首选项”)下选择“用户代码段”,然后选择语言。在文件中写入以下内容并保存:
{
"Default file": {
"prefix": "main",
"body": ["#include <iostream>", "#include <iomanip>", "#include <math.h>", "\nusing namespace std;", "\nint main() {", "\nreturn 0;", "\n}"],
"description": "My default cpp file"
}
}
现在,在某些* .cpp文件中,开始写“ main”,VSCODE将向您显示完整的单词。只需点击tab并瞧瞧。