在 VS 代码上调试 C++ 时,终端不显示任何输入和输出

时间:2020-12-19 03:59:52

标签: c++ visual-studio-code

当我在 VS 代码上尝试一个非常简单的 C++ 代码时:

#include<iostream>
using namespace std;

int main()
{
    int a;
    cout<<"Please input: "<<endl;
    cin>>a;
    cout<<a<<endl;
    system("pause");
    return 0;
}

按F5输入数字后,发现终端里没有结果,是这样的: First Debug

然后按 Ctrl+F5 停止调试后,显示数字和结果: Second Debug

下面是我的配置文件:

tasks.json

// tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build", 
            "type": "shell", 
            "command": "g++", 
            "args": [    
                "${file}", 
                "-o", 
                "${fileDirname}\\bin\\${fileBasenameNoExtension}.exe",
                "-g", 
                //"-Wall", 
                //"-static-libgcc",  
                // "-fexec-charset=GBK", 
            ],
            "group": {  
                "kind": "build",
                "isDefault": true
            },
            "presentation": { 
                "echo": true,
                "reveal": "always", 
                "focus": false, 
                "panel": "new" 
            },
            "problemMatcher": "$gcc" 
        },
        {
            "label": "run", 
            "type": "shell", 
            "dependsOn": "build", 
            "command": "${fileDirname}\\bin\\${fileBasenameNoExtension}.exe",
            "group": {
                "kind": "test", 
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": true, 
                "panel": "new"
            }
        }

    ]
}

launch.json

// launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug", 
            "type": "cppdbg", 
            "request": "launch", 
            "program": "${fileDirname}\\bin\\${fileBasenameNoExtension}.exe", 
            "args": [], 
            "stopAtEntry": false, 
            "cwd": "${fileDirname}", 
            "environment": [], 
            "externalConsole": false, 
            "internalConsoleOptions": "neverOpen", 
            "MIMode": "gdb", 
            "miDebuggerPath": "D:\\Program Files\\mingw-w64\\bin\\gdb.exe", 
            "preLaunchTask": "build" 
    }]
}

setting.json

// setting.json
{
    "files.associations": {
        "iostream": "cpp",
        "map": "cpp",
        "istream": "cpp",
        "*.tcc": "cpp",
        "deque": "cpp",
        "list": "cpp",
        "string": "cpp",
        "unordered_map": "cpp",
        "vector": "cpp",
        "ostream": "cpp"
    },
    "cmake.configureOnOpen": false
}

如果有人能帮助我,我将不胜感激!

0 个答案:

没有答案