I'm brand new to MacOS and I am attempting to set up a programming environment, my IDE of choice being Visual Studio Code. When the program runs it, by default, prints in output. However, output crashes when asked to gather input. The online solution the I found for that was to output the code through the terminal, yet now nothing is displayed in the terminal.
I'm posting this here instead of a bug report as I'm unsure whether the fault is mine or the program's.
Here is the simple code I am attempting to run:
#include <iostream>
int main()
{
int i;
std::cout << "Enter a number: ";
std::cin >> i;
std::cout << "\n" << i;
return 0;
}
When run through output, it will display the first part, then crash when input is requested. When run through the terminal, the terminal only displays: "cd "(directory location)" && g++ main.cpp -o main && "(directory location)"main" and nothing else.
Below are my tasks.json and 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"
}
]
}
The only setting that has been changed would be "code-runner.runInTerminal" which has been set to true.
This is true when using Code Runner
so the solution is:
use Code Runner and then press Ctrl+,
to edit settings then search forcode-runner.runInTerminal
and set code-runner.runInTerminal
to true
, like so:
{
"code-runner.runInTerminal": true
}
this works fine for me.
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With