Reputation: 1742
Mac OS: Catalina 10.15.7
Steps to reproduce problem:
Install Xcode and vs code in Mac.
Install c++ extension in vs code.
create a folder called cpp01.
Open that folder in vs code.
Create a file called cpp01.cpp and copy the following contents inside that file.
#include <iostream>
using namespace std;
int main() {
int intYear;
cout << "Enter Year: ";
cin >> intYear;
cout << "You have entered year: " << intYear << "\n";
}
Select "Run" -> "Run Without Debugging"
Select "C++ (GDB/LLDB)"
Select "Clang ++ - Build and debug active file"
Expected output in the Terminal (or if I run the same program in Windows or Linux, I should be able to see the following output in the Terminal):
Enter Year:
Then I should be able to enter the year.
However, the Actual Output when running this program in Mac OS is:
Executing task: /usr/bin/clang++ -g /Users/abc/vscode/cpp/cpp01/cpp01.cpp -o /Users/abc/vscode/cpp/cpp01/cpp01 <
Terminal will be reused by tasks, press any key to close it.
Then if I press any key in the terminal, it simply close the terminal. And I'll never be able to enter the year.
i.e. The behavior of running this program is COMPLETELY DIFFERENT in Mac OS.
So, how can I run the program by using "Run" -> "Run without Debugging"? (Note, I can compile the program and run it in an external terminal by using the command "./programname", I just can't run it using the "Run without Debugging", which I am able to do so in Windows or Linux)
These are some more information:
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=thread-selected,id="1"
=library-unloaded,id="/Users/abc/vscode/cpp/cpp01/cpp01",target-name="/Users/abc/vscode/cpp/cpp01/cpp01",host-name="/Users/abc/vscode/cpp/cpp01/cpp01"
Loaded '/usr/lib/dyld'. Symbols loaded.
Loaded '/Users/abc/vscode/cpp/cpp01/cpp01'. Symbols loaded.
Loaded '/usr/lib/libc++.1.dylib'. Symbols loaded.
Loaded '/usr/lib/libSystem.B.dylib'. Symbols loaded.
Loaded '/usr/lib/libc++abi.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libcache.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libcommonCrypto.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libcompiler_rt.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libcopyfile.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libsystem_networkextension.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libsystem_notify.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libsystem_sandbox.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libsystem_secinit.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libsystem_kernel.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libsystem_platform.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libsystem_pthread.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libsystem_symptoms.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libsystem_trace.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libunwind.dylib'. Symbols loaded.
Loaded '/usr/lib/system/libxpc.dylib'. Symbols loaded.
Loaded '/usr/lib/libobjc.A.dylib'. Symbols loaded.
@"Enter Year: "
{
"tasks": [
{
"type": "shell",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C++: clang++ build active file"
}
]
}
Thank you
Upvotes: 1
Views: 5219
Reputation: 11
Run from an external console. In launch.json:
"externalConsole": true,
Upvotes: 1