c++terminalmingwmingw-w64debug-console

C++ Output in Debug Console instead of Terminal or Output window (Visual Studio Code)


I have the following problem that when I debug my project in Visual Studio Code, all outputs are shown in the debug console. But i want it in the terminal window or output window. How can i change that? I already tried so much by editing the launch.json tasks.json and c_cpp_properties.json or using extensions. The bigger problem is that I dont get the full output in the Debug Console, some outputs are missing. I downloaded the MinGW64 Compiler Version "g++ (MinGW.org GCC-6.3.0-1) 6.3.0".

With the command "g++ -o ..." everything works and I get the output on the console, but i want to use F5 or ctrl+F5 in Visual studio Code and not manually write "g++ -o ..." (or arrow up key) everytime I wanna debug.

(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;
}

(calculations.h)

#include <iostream>

int add(int, int);

int sub(int, int);

void output_message(std::string);

(calculations.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
}

(launch.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"
}

(tasks.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"
}

(Debug Console Output. Output from hi("-") and cout << sub(1,2) is missing) Debug Console Output. Output from hi("-") and cout << sub(1,2) is missing


Solution

  • solved it by uninstalling MinGW and installing it via Msys2