本文主要为了在云端存储自己成功配置的文件,不提供详细的操作流程。
1.先在VSCODE中下载 C/C++ 相关的插件,然后下载mingw64解压到本地,将mingw64的bin加入系统环境变量的path中。
2.在vscode中运行c/c++时,会在c/c++文件的父目录生成 .vscode文件夹,该文件夹包括c_cpp_properties.json,launch.json,settings.json,tasks.json(这个tasks可能一开始没有,执行程序时才会出现)
3.c_cpp_properties.json配置:
{
"configurations": [
{
"name": "Win32",
"includePath": ["${workspaceFolder}/**"],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "D:\\Program Files\\mingw64\\bin\\g++.exe", /*修改成自己bin目录下的g++.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "${default}"
}
],
"version": 4
}
4.launch.json配置:
{
"version": "0.2.0",
"configurations": [
{
"name": "(HUX3273)g++.exe 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program":"${workspaceFolder}/exe/${fileBasenameNoExtension}.exe", // 在文件夹里创建一个exe文件夹专门放程序文件
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\Program Files\\mingw64\\bin\\gdb.exe", /*修改成自己bin目录下的gdb.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask":"C/C++: g++.exe 生成活动文件" // 与tasks文件中的label保持同名
}
]
}
5.settings.json配置:(一般不用修改)
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false,
"files.associations": {
"array": "cpp",
"string": "cpp",
"string_view": "cpp"
}
}
6.tasks.json配置:
{
"version": "2.0.0",
"tasks": [
{
"label": "C/C++: g++.exe 生成活动文件",
"type": "shell",
"command": "g++",
"args": [
"-finput-charset=UTF-8",
"-fexec-charset=GBK",
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${workspaceFolder}/exe/${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
此时按F5开始调试,ctrl+F5不调试直接运行。