1.摘要
在使用Vscode编译单个文件网上很多教程,但是对多个文件编译会发现经常出问题,通过不断的借阅网友的教程改进终于完成C++运行多个文件教程如下:
2.编译运行过程
2.1 初始配置过程
(1)Vscode以及MinGW配置教程很多自行查阅。
(2)在文件下建立.vscode
(3) 接着在.vscode文件夹并创建3个文件,分别是c_cpp_properties.json,launch.json,tasks.json
2.2 文件内容
2.2.1 c_cpp_properties.json
{"configurations": [{"name": "Win32","includePath": ["${workspaceFolder}/**"],"defines": ["_DEBUG", "UNICODE", "_UNICODE"],"windowsSdkVersion": "10.0.17763.0",/*修改成自己bin目录下的g++.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/"compilerPath": "D:\\IE_Download\\demoapp\\VScode\\mingw64\\bin\\g++.exe", "cStandard": "c11","cppStandard": "c++17","intelliSenseMode": "${default}"}],"version": 4
}
2.2.2 launch.json
{// 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "g++.exe build and debug active file","type": "cppdbg","request": "launch","program": "${fileDirname}\\${fileBasenameNoExtension}.exe","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": true,"MIMode": "gdb","miDebuggerPath": "D:\\IE_Download\\demoapp\\VScode\\mingw64\\bin\\gdb.exe", /*修改成自己bin目录下的gdb.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/"setupCommands": [{"description": "为 gdb 启用整齐打印","text": "-enable-pretty-printing","ignoreFailures": true}],"preLaunchTask": "task g++"}]
}
2.2.3 tasks.json
{// See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format"version": "2.0.0","tasks": [{"type": "shell","label": "task g++","command": "D:\\IE_Download\\demoapp\\VScode\\mingw64\\bin\\g++.exe", /*修改成自己bin目录下的g++.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/"args": ["-g",// "${file}","${fileDirname}\\*.cpp", //"${fileDirname}\\*.cpp"是搜索到当前目录的所有cpp文件"-o", //-o创建当前目录下所有cpp文件的目标文件并链接"${fileDirname}\\${fileBasenameNoExtension}.exe",//将链接好的exe文件放入当前目录下的bin目录下(这个可以随便设置)"-I","D:\\deks\\C++", /*修改成自己放c/c++项目的文件夹,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/"-std=c++17"],"options": {"cwd": "D:\\IE_Download\\demoapp\\VScode\\mingw64\\bin" /*修改成自己bin目录,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/},"problemMatcher":["$gcc"],"group": "build",}]
}
注意以上文件路径的修改 然后运行自己的文件就可以了。