本人没使用系统cmd窗口,而是使用了vscode内置终端,目的是为了之后输出中文的时候不乱码(vscode是utf-8,cmd是gbk,干脆全部使用vscode,不使用系统cmd作为输出窗口)
附上配置文件:
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
// "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
// "args": [],
"program": "C:\\Windows\\System32\\cmd.exe",
"args": ["/c","${fileDirname}\\${fileBasenameNoExtension}.exe","&","pause"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false, // 修改此项为true,运行时可以弹出console终端,此处不使用系统终端,故为false
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe 生成活动文件"
}
]
}
task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "C:\\Program Files\\mingw64\\bin\\g++.exe",
"args": [
// "-fexec-charset=GBK", //这里没用到系统终端,故不改成gbk格式
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
标签:exe,vecode,cmd,c++,乱码,fileDirname,gdb,++.
From: https://www.cnblogs.com/hisun9/p/18473156