【问题标题】:How do I make vs code put the output of my c program in TERMINAL panel?如何使 vs code 将我的 c 程序的输出放在 TERMINAL 面板中?
【发布时间】:2021-10-31 10:25:02
【问题描述】:

我正在尝试在 Windows 10 上使用 vscode 构建和运行 C 代码。

我浏览了vscode doc for mingw configuration,按照那里的步骤并设法使用 vscode 运行了一个 .c 文件。

但是,还有一个问题。

每次通过“Run | Run without Debugging”运行我的程序时,面板会自动切换到“TERMINAL”

所以每次运行代码都得手动切换到DEBUG CONSOLE,很乏味。

有没有办法让“DEBUG CONSOLE”面板保持活动状态或在“TERMINAL”面板中显示我的程序输出

我也在另一个stackoverflow post 中尝试过这个建议,但它对我不起作用。

tasks.json

这是我的 tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe build active file",
            "command": "E:\\MinGW\\bin\\gcc.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: E:\\MinGW\\bin\\gcc.exe"
        }
    ]
}

launch.json

这是我的 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": "gcc.exe - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "E:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc.exe build active file"
        }
    ]
}

如何使 vs code 将我的 c 程序的输出放在 TERMINAL 面板中?

【问题讨论】:

    标签: visual-studio-code


    【解决方案1】:

    您可以通过一些简单的配置使用Code Runner

    1. 安装Code Runner
    2. 输入Ctrl + Shift + P
    3. 搜索并打开Open Settings(JSON)
    4. 将以下 json sn-ps 添加到您的 settings.json:
        "code-runner.runInTerminal": true
    
    1. 每次要运行 c 代码时,只需键入 Code Runner 提供的右上角的图标即可。

    对于第 4 步,您还可以打开 vscode 设置并在 GUI 上进行更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 1970-01-01
      • 2020-01-29
      • 2023-02-06
      • 2022-12-01
      • 2022-12-29
      相关资源
      最近更新 更多