我是 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/