【发布时间】: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