相关疑难解决方法(0)

使用VSCode在Python中调试期间读取输入

这是我在vs代码中使用的python扩展:python扩展.

当我使用扩展程序提供的调试功能时,如果需要从命令行输入,它将挂在那里并且什么也不做.

在哪里可以输入值来跨越vs代码中的输入语句?

python visual-studio-code

12
推荐指数
2
解决办法
1万
查看次数

在调试控制台 VScode 中使用输入(stdin)

我尝试在 VS Code 中调试一些代码。一切正常,但是当我尝试在控制台中输入某些内容时,什么也没有发生。

我的代码:

#include <stdio.h>

#define SIZE 20

int main()
{
    char arr[SIZE];
    
    fgets(arr, SIZE, stdin);

    puts(arr);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我过去常常fgets()从控制台读取字符串,但是当调试到达函数时,一切都会停止,我无法输入任何内容。

在此输入图像描述

只是黑窗。

但是,当我使用 时gets(),就像这个例子一样:

#include <stdio.h>

#define SIZE 20

int main()
{
    char arr[SIZE];
    
    gets(arr);

    puts(arr);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

一切正常。

在此输入图像描述

哪里有问题?也许调试控制台无法读取任何内容?我怎样才能使用输入任何内容fgets()

这是我的 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": …
Run Code Online (Sandbox Code Playgroud)

c debugging stdin fgets visual-studio-code

12
推荐指数
1
解决办法
1万
查看次数

Visual Studio代码在调试时使用输入文本文件

我试图按照这篇文章的指示

调试时Visual Studio代码重定向输入

但是当我将控制台配置添加到launch.json文件时

"console": "integratedTerminal"
Run Code Online (Sandbox Code Playgroud)

它抛出"不允许属性控制台".当我调试程序时,它仍然等待输入,并且永远不会达到断点,就像我开始在shell中一样

"./a.out 1 test1.txt"

"./a.out 1 <test1.txt"    
Run Code Online (Sandbox Code Playgroud)

完整配置

{
    "version": "0.2.0",
    "configurations": [

    {
        "name": "(lldb) Launch",
        "type": "cppdbg",
        "request": "launch",
        //"program": "${workspaceRoot}/a.out.dSYM/Contents/Resources/DWARF/a.out",
        "program": "${workspaceRoot}/a.out",
        "args": ["1", "<","test1.txt"],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}/",
        "environment": [],
        "externalConsole": true,
        "MIMode": "lldb",
        //"miDebuggerPath": "C:\\mingw\\bin\\gdb.exe",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "console": "integratedTerminal"
        //"preLaunchTask": //"build test1"
    }
]
Run Code Online (Sandbox Code Playgroud)

}

c++ visual-studio-code

5
推荐指数
1
解决办法
1359
查看次数

在 Visual Studio Code 中用 C++ 调试时如何读取输入?

我正在使用VSCodeMacOSX 中调试我的CPP程序。

我有2个程序。

程序1

int main(){

    string a;
    a = "a";
    a += 'b';
    cout<<a<<endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

程序2

int main(){

    string a;
    cin>>a;
    a += 'b'
    cout<<a;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

program1 中,我直接分配string a和 当我调试程序时VSCode,首先使用以下命令在终端中编译它:

g++ -g filename.cpp

然后在调试菜单中选择开始调试选项。我可以通过在断点中向前移动来查看变量的状态。string a

变量部分显示不同的变量的状态和CALL堆栈显示堆栈帧。

但是,对于program2,当我越过 的断点时cin>>a;VARIABLESCALL STACK的内容将被清除。

以下是launch.json文件的内容:

{
    "version": "0.2.0",
    "configurations": …
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio-code

5
推荐指数
3
解决办法
1万
查看次数

标签 统计

visual-studio-code ×4

c++ ×2

c ×1

debugging ×1

fgets ×1

python ×1

stdin ×1