【问题标题】:C++ Terminal Not Working in Visual Studio CodeC++ 终端在 Visual Studio 代码中不起作用
【发布时间】:2021-04-08 10:01:22
【问题描述】:

我有一个 C++ 程序。这个程序不工作。我将"externalConsole": false 更改为"externalConsole": true,它可以工作并且给了我控制台。但我想用"externalConsole": false 运行。有没有办法做到这一点?相关输出如下。

程序 (asd.cpp)

#include <iostream>
using namespace std;

int main()
{
    int x  = 1525, z;
    cout << "x number is " << x << endl;
    cin >> z;
    cout << "z number 2 is " << z << endl;
    getchar();
}

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": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/asd.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/MinGW/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

终端

Windows PowerShell

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\hakan\projects\onecpp>  & 'c:\Users\hakan\.vscode\extensions\ms-vscode.cpptools-1.3.0-insiders4\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-emhvpzpo.syb' '--stdout=Microsoft-MIEngine-Out-dht4nkur.p5d' '--stderr=Microsoft-MIEngine-Error-cpkcr2pw.mzq' '--pid=Microsoft-MIEngine-Pid-v2fsb4cd.no1' '--dbgExe=C:/MinGW/bin/gdb.exe' '--interpreter=mi' 
PS C:\Users\hakan\projects\onecpp> 

调试控制台

=thread-group-added,id="i1"
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
=cmd-param-changed,param="args",value="2>CON 1>CON <CON"
[New Thread 9284.0x16f4]
x number is 1525
z number 2 is 1013
The program 'C:\Users\hakan\projects\onecpp\asd.exe' has exited with code 0 (0x00000000).

我做了一个程序输入数据,我不能输入数据,它写了1013。

构建正在运行:Build finished successfully.

【问题讨论】:

  • 从调试控制台输出看来它工作正常?
  • 可以,但是我做一个程序输入数据时,无法输入数据,程序直接关闭。
  • 我想如果你想使用标准输入那么你需要使用外部控制台
  • 显然这就是vscode中需要做的事情。

标签: c++ visual-studio-code vscode-debugger


【解决方案1】:

不推荐使用设置"externalConsole": false。尝试将 "console": "integratedTerminal" 与最新版本的 Visual Studio Code 一起使用。对我来说,集成终端中的控制台输入可以正常工作。

【讨论】:

  • 没有任何改变。 Property console is not allowed. 发出警告。
  • @en0ndev 似乎不同之处在于您使用的是 cppdbg。有了那个和MinGW我有同样的问题。由于您的输出是 asd.exe 我假设您使用的是 Windows。尝试将“type”:“cppvsdbg”与“console”:“integratedTerminal”一起使用。这应该有效。
  • 看起来它会工作,但我没有得到任何输出。 imgur.com/saSgIn2
  • @en0ndev 您正在查看“调试控制台”选项卡。那是错误的,您的应用程序控制台输入/输出转到“终端”。我不得不承认这是非常具有误导性的。
  • 终端调试没有变化。 imgur.com/gjgaLWH
猜你喜欢
  • 1970-01-01
  • 2019-04-03
  • 1970-01-01
  • 2019-06-23
  • 1970-01-01
  • 1970-01-01
  • 2021-05-26
  • 1970-01-01
  • 2016-09-15
相关资源
最近更新 更多