【发布时间】: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