VSCode仅在调试模式下显示输出

时间:2019-11-03 17:21:45

标签: c++ visual-studio-code ubuntu-18.04

我开始使用C ++在VSCode中工作。 我使用Ubuntu 18.04,G ++编译7.4.0,VSCode 1.39.2 我创建了简单的test.cpp

#include <string>
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    /* code */
    cout << "Hello, world";
    getchar();
    return 0;
}

并配置我的launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++ build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "MyDefaultTask",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

task.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "MyDefaultTask",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build"
        }
    ]
}

使用调试模式( F5 )时,一切正常:

enter image description here

但是运行Task( Ctrl + Shift + B )时看不到输出: enter image description here

如何查看程序输出(和控制台,因为我想在程序中使用键盘输入)?

0 个答案:

没有答案