c++ - Visual Studio Code 集成终端不显示文本

标签 c++ terminal visual-studio-code

我是 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”(目录位置)“&& g++ main.cpp -o main &&”(目录位置)“main”,没有其他内容。

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

任务.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
            }
        }
    ]
}

启动.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"
            }
        ]
    }

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

最佳答案

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

{
    "code-runner.runInTerminal": true
}

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

关于c++ - Visual Studio Code 集成终端不显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46464525/

相关文章:

javascript - 如何在特定的 URL 中启动 Node.js?

visual-studio-code - 如何在 Visual Studio Code 中自定义 HTML 标签的颜色?

visual-studio-code - VSCode 远程 server.sh 在 wsl docker-desktop 中找不到节点

c++ - 从参数包中提取成员类型

linux - 在 Linux 终端/Putty 中改变一个字的颜色?

c++在复制构造函数中使用const?

python - 使 osascript 交互式/实时打印标准输出

powershell - 如何调整 VSCode 对 PowerShell 的支持——更好地处理引号的输入

c++ - isalpha 总是返回 0

c++ - linux中线程和进程的性能