fur*_*fur 9 visual-studio-code
在 CodeBlocks 中,可以设置每次创建新文件时都会打开的代码。一种代码模板或骨架。
如何设置默认代码以在 Visual Studio Code C++ 中打开,以便每次创建新文件时都不必编写它?我的意思是,我需要它来显示以下代码,而不是创建一个空白文件:
#include <iostream>
using namespace std;
int main(){
}
Run Code Online (Sandbox Code Playgroud)
Gin*_*pin 13
您可以使用文件模板扩展名。
C++ 文件不包括在其支持的文件类型的默认列表中。但它确实支持为已知的 VS Code 语言标识符添加您自己的模板,例如.cpp
C++ 文件。
要进行设置,请按照扩展程序页面上的说明进行操作:
gino@templates$ pwd
/Users/gino/.vscode/extensions/ralfzhang.filetemplate-2.0.4/asset/templates
Run Code Online (Sandbox Code Playgroud)
gino@templates$ vim cpp.tmpl
gino@templates$ cat cpp.tmpl
#include <iostream>
using namespace std;
int main(){
}
Run Code Online (Sandbox Code Playgroud)
要使用它:
.cpp
扩展名的文件该.cpp
文件将由cpp.tmpl
.
如果你想对你的模板感兴趣,根据扩展的文档,模板遵循TextMate 语法。在我上面的例子中,我只使用了普通的 C++ 代码,它工作正常。
小智 6
(片段代码采用 JSON 格式)
// Write this code in the cpp.json file
{
"cpp snippets":
{
"prefix" : "basic",
"body" : [
"#include<iostream>",
"using namespace std;",
"int main()",
"{",
" return 0;",
"}"
],
"description" : "c++ basic"
}
}
Run Code Online (Sandbox Code Playgroud)
要创建自定义片段代码,请检查此
归档时间: |
|
查看次数: |
10565 次 |
最近记录: |