1、新建一个main.cpp文件
#include <iostream>
using namespace std;
int main() {
cout <<"vc code main"<<" \n";
system("pause");
return 0;
}
2、生成launcher.json和tasks.json



3、修改launcher.json和tasks.json如下位置
launcher.json

tasks.json

?4、运行(选中主函数所在文件 按F5)

?运行结果如下:

5、在项目中添加.h头文件
新增include/date.h文件
#ifndef DATE_H
#define DATE_H
int getDate();
#endif
新增date.cpp文件
#include <iostream>
#include "include/date.h"
int getDate() {
std::cout<<"vs code getDate \n";
return 0;
}
修改task.json如下(将date.cpp和main.cpp添加到tasks.json中)
{
"tasks": [
{
"type": "cppbuild",
"label": "g++",
"command": "D:\\worksoft\\TMD-GCC\\TDM-GCC-64\\TDM-GCC-64\\bin\\g++.exe",
"args": [
"-g",
"${workspaceFolder}/date.cpp",
"${workspaceFolder}/main.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
选中主函数按F5编译,编译结果如下

源码GitHub地址如下:git@github.com:hejiangzhou1/FIRST_VS_CODE_PROJECT.git
|