vscode设置用户自定义c++代码片段
点击VScode左下角齿轮->点击用户代码片段->输入cpp.json
在json文件输入以下内容,可以自行修改内容。注意下面代码要放到json的{ }内
"Print to conaole": {
"prefix": "C++", //在新建立的页面中输入C++就会有提示,Tab就自动生成好了,也可以自己重新起名
"body": [
"#include <iostream>",
"#include <string>",
"#include \"../share/fmt/format.h\"",
"#include \"../share/src/format.cc\"",
"", // 空行
"using namespace std;", //标准命名空间
"namespace std // std的扩展",
"{"
" using fmt::format;",
" using fmt::format_error;",
" using fmt::formatter;",
"} // namespace std",
"",
"int main()", //main()函数
"{",
" $0", //最终光标会在这里等待输入
" return 0;", //结束
"}",
"",
],
"description": "A cpp file template." //用户输入后智能提示的内容(你可以用中文写“生成C++模板等你喜欢的内容”)
}
注意事项:body每一行的内容都是" “符号包裹的,如果需要输出的符号是”,那么需要使用转义字符’ \ '来修饰,如第6行!
最后保存即可!