在vscode中ctrl + shift + p,
配置snippet
{
// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
//在h文件中避免重复包含
"Print to header":{
"prefix": "header",
"body": [
"#ifndef ${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H",
"#define ${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H",
"#endif // $1",
"/*Created: wang on $CURRENT_YEAR_SHORT/$CURRENT_MONTH/$CURRENT_DATE.*/",
],
"description": "A cpp file template."
},
//在c文件中包含相应的头文件
"include header":{
"prefix": "cpp",
"body": [
"#include \"${TM_FILENAME_BASE}.h\""
],
"description": "A cpp file template."
},
//main函数模板
"main":{
"prefix": "main",
"body": [
"#include <iostream>",
"#include <stdint.h>",
"using namespace std;",
"int main(void)",
"{",
" return 0;",
"}"
],
"description": "A cpp file template."
},
}