一直在用codeRunner运行程序,知道遇到了一个bug,需要用到断点功能,于是试了下F5。 发现终端框输入不了,并且运行代码有的代码没有输出,奇怪的bug,后找了许多解决方案,有的能在外部终端cmd正常运行,有的报错,有的“此时不应有 &”的各种奇形怪状的问题。偶然发现笔记本的就很正常,对比了一下环境。 最后发现是台式机重装了系统后装的MinGW是32位的,笔记本是64的,在重装了个64的mingw并添加了path重启电脑后,整个程序正常了,消耗了一下午时间得来的经验。 另附上我的各Json配置文件数据,给大家作参考,也给自己留个备份。 使用如下json理论上可以在coderunner和调试运行的时候都用vsc的内置终端,并可以输入输出。各参数有的加了注释,按自己需求来改吧。 launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"internalConsoleOptions": "neverOpen",
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "Compile"
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:\\mingw64\\bin\\gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "${default}"
}
],
"version": 4
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile",
"command": "g++",
"args": [
"${file}",
"-I",
"D:/code/Default",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-g",
"-m64",
"-Wall",
"-static-libgcc",
"-fexec-charset=GBK",
"-D__USE_MINGW_ANSI_STDIO",
],
"type": "process",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"problemMatcher": "$gcc"
}
]
}
setting.json
{
"files.defaultLanguage": "c",
"editor.formatOnType": true,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"editor.acceptSuggestionOnEnter": "off",
"code-runner.runInTerminal": true,
"code-runner.saveFileBeforeRun": true,
"code-runner.preserveFocus": false,
"code-runner.clearPreviousOutput": false,
"code-runner.ignoreSelection": true,
"code-runner.fileDirectoryAsCwd": true,
"C_Cpp.clang_format_sortIncludes": true,
"files.associations": {
"ostream": "cpp",
"iostream": "cpp",
"vector": "cpp",
"xstring": "cpp",
"cmath": "cpp"
},
"C_Cpp.clang_format_style": "chromium",
}
|