环境配置完成了,简单的C++程序也能写,但是最近要求要写头文件、MAIN.CPP、类声明的cpp文件,然后不知道要怎么整合在一起,就是写的好好的调试执行时,说无法打开xxx.h xxx.cpp 所以想问一下怎么像VS那样放在一个工程项目。。。
打开项目,建立头文件:头文件->添加->新建项->头文件;建立cpp文件:头文件->添加->新建项->C++文件。在
源文件中添加刚刚建的头文件,main函数放在cpp文件中,然后生成解决方案,ctrol+F5执行。
新建的时候直接建立空项目就行,在这个项目里,有源文件,头文件之类的
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "g++",
"args":["-g",
"${workspaceRoot}/main.cpp",
"-o",
"${workspaceRoot}/a.out"
],
"group":{
"kind":"build",
"isDefault":true,
}
}
]
}
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}