我遇到以下问题:当我在 Visual Studio Code 中调试项目时,所有输出都显示在调试控制台中。但我希望它出现在终端窗口或输出窗口中。我怎样才能改变这一点? 我已经通过编辑 launch.json、tasks.json 和 c_cpp_properties.json 或使用扩展进行了很多尝试。更大的问题是我没有在调试控制台中获得完整的输出,一些输出丢失了。 我下载了 MinGW64 编译器版本“g++ (MinGW.org GCC-6.3.0-1) 6.3.0”。
使用命令“g++ -o ...”一切正常,我在控制台上得到输出,但我想在 Visual Studio Code 中使用 F5 或 ctrl+F5 而不是手动编写“g++ -o ...”(或向上箭头键)每次我想调试时。
(main.cpp)
#include <iostream>
#include "includes/calculations.h"
using namespace std;
int hi(string message)
{
cout << message << endl;
}
int main()
{
cout << add(1, 2) << endl;
cout << sub(1, 2) << endl;
output_message("HI");
hi("-");
return 0;
}
(计算.h)
#include <iostream>
int add(int, int);
int sub(int, int);
void output_message(std::string);
(计算.cpp)
#include <iostream>
int add(int x, int y)
{
return x + y;
}
int sub(int x, int y)
{
return x - y;
}
void output_message(std::string message)
{
std::cout << message << std::endl;
}
(c_cpp_properties.json)
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${vcpkgRoot}/x86-windows-static/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
(启动.json)
{
"configurations": [
{
"name": "C/C++: g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false, // Opens external Window, but i want in in Visual Studio Code to be opend
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
],
"version": "2.0.0"
}
(任务.json)
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"src/*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
通过卸载 MinGW 并通过 Msys2 安装来解决它