问题遇到的现象和发生背景
可能是因为前一段时间下载了一个背景插件.那时候一直报错说code文件损坏.当时代码都能正常运行所以我也没管.可最近一运行代码就报错(如标题)
操作环境、软件版本等信息
win10 vscode mingw8.1.0
代码路径:D:\Program Files\Code
尝试过的解决方法
去csdn上搜了一大堆方法,都没啥用.文件路径也不是中文,vscode也彻底删除重新下载了.mingw也重新下载了8.1.0,还跟着别人改了各种launch和tasks,都没用,实在是走投无路了,希望好人能帮帮我
我想要达到的结果
正常运行
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件", //⭐此处cpp改为了g++
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "D:\\Program Files\\mingw64\\bin",
"environment": [],
"externalConsole": true,//⭐false改为true
"MIMode": "gdb",
"miDebuggerPath": "D:\\Program Files\\mingw64\\bin\\gdb.exe",//⭐此处路径为mingw64中bin中g++.exe路径,要根据自己按的位置做修改
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "task g++"
}
]
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "task g++",
"command": "D:\\Program Files\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\Program Files\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
],
"group": "build",
"detail": "compiler: cl.exe"
}
],
"version": "2.0.0"
}{
"tasks": [
{
"type": "cppbuild",
"label": "task g++",
"command": "D:\\Program Files\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\Program Files\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
],
"group": "build",
"detail": "compiler: cl.exe"
}
],
"version": "2.0.0"
}
setting.json
{
"files.defaultLanguage": "cpp", // ctrl+N新建文件后默认的语言
"editor.formatOnType": true, // 输入时就进行格式化,默认触发字符较少,分号可以触发
"editor.snippetSuggestions": "top", // snippets代码优先显示补全
"code-runner.runInTerminal": true, // 设置成false会在“输出”中输出,无法输入
"code-runner.executorMap": {
"c": "cd $dir && clang $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics --target=x86_64-w64-mingw -std=c11 && $dir$fileNameWithoutExt",
"cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -fcolor-diagnostics --target=x86_64-w64-mingw -std=c++17 && $dir$fileNameWithoutExt"
}, // 设置code runner的命令行
"code-runner.saveFileBeforeRun": true, // run code前保存
"code-runner.preserveFocus": true, // 若为false,run code后光标会聚焦到终端上。如果需要频繁输入数据可设为false
"code-runner.clearPreviousOutput": false, // 每次run code前清空属于code runner的终端消息
"C_Cpp.clang_format_sortIncludes": true, // 格式化时调整include的顺序(按字母排序)
"C_Cpp.intelliSenseEngine": "Default", // 可以为Default或Tag Parser,后者较老,功能较简单。具体差别参考cpptools扩展文档
"C_Cpp.errorSquiggles": "Disabled", // 因为有clang的lint,所以关掉
"C_Cpp.autocomplete": "Disabled", // 因为有clang的补全,所以关掉
"clang.cflags": [ // 控制c语言静态检测的参数
"--target=x86_64-w64-mingw",
"-std=c11",
"-Wall"
],
"clang.cxxflags": [ // 控制c++静态检测时的参数
"--target=x86_64-w64-mingw",
"-std=c++17",
"-Wall"
],
"clang.completion.enable": true,
"files.associations": {
"algorithm": "cpp"
} // 效果效果比cpptools要好
}
c_cpp_properties.json
{
"configurations": [
{
"name": "MinGW",
"intelliSenseMode": "gcc-x64",
"compilerPath": "D:\\Program Files\\mingw64\\bin\\g++.exe",//⭐此处路径为mingw64中bin中g++.exe路径,要根据自己按的位置做修改
"includePath": [
"${workspaceFolder}"
],
"defines": [],
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}