【问题标题】:Visual Studio Code Integrated Terminal not Displaying TextVisual Studio Code 集成终端不显示文本
【发布时间】:2018-03-09 22:11:25
【问题描述】:

我是 MacOS 的新手,我正在尝试设置一个编程环境,我选择的 IDE 是 Visual Studio Code。当程序运行时,默认情况下会在输出中打印。但是,当要求收集输入时,输出会崩溃。我找到的在线解决方案是通过终端输出代码,但现在终端中没有显示任何内容。

我在这里发布这个而不是错误报告,因为我不确定故障是我的还是程序的。

这是我尝试运行的简单代码:

#include <iostream>

int main()
{
    int i;
    std::cout << "Enter a number: ";
    std::cin >> i;
    std::cout << "\n" << i;
    return 0; 
}

运行输出时,它会显示第一部分,然后在请求输入时崩溃。通过终端运行时,终端只显示:"cd "(directory location)" && g++ main.cpp -o main && "(directory location)"main" 没有别的。

下面是我的tasks.json和launch.json:

tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "c++ test program",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g", "main.cpp"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

launch.json:

{
        "version": "0.2.0",
        "configurations": [
            {
                "name": "(lldb) Launch",
                "type": "cppdbg",
                "request": "launch",
                "program": "${workspaceRoot}/a.out",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${workspaceRoot}",
                "environment": [],
                "externalConsole": true,
                "MIMode": "lldb"
            }
        ]
    }

唯一更改的设置是“code-runner.runInTerminal”,它已设置为 true。

【问题讨论】:

  • 您是否在终端中运行./a.out 命令?由于您显示它用于编译程序的命令 - 不运行它。编译 VSCode 中的代码。打开终端(内置或外部)并运行ls - 看到生成了 a.out。运行./a.out
  • 使用任一终端在键入任一命令或同时键入两个命令时都不会发生任何事情。看来代码编译但没有运行。

标签: c++ terminal visual-studio-code


【解决方案1】:

使用Code Runner 时确实如此 所以解决方案是:
使用Code Runner,然后按Ctrl+, 编辑设置,然后搜索
code-runner.runInTerminal 并将code-runner.runInTerminal 设置为true,如下所示:

{
    "code-runner.runInTerminal": true
}

这对我来说很好。
我希望这会有所帮助。

【讨论】:

  • 在提问之前我已经这样做了。如果设置为 false,代码将一直运行,直到请求输入。如果设置为 true,则代码根本不会运行。
  • 尝试更改VSCode集成终端,可能是this帮助:Mac OS X: Change shell for integrated terminal
  • 没关系,我想通了。我搞砸了我做其他事情的路径,并扩展了我的终端。我能够通过删除 .bash_profile 来修复它。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-19
  • 1970-01-01
  • 2017-05-13
  • 2017-09-04
  • 2023-02-18
  • 1970-01-01
相关资源
最近更新 更多