DEV Community

Cover image for Debugging C++ in macOS
Abhishek S
Abhishek S

Posted on

Debugging C++ in macOS

Cover photo by Clément H on Unsplash

Trying to figure out how to add user input while debugging C++ on macOS in VScode? You've come to the right place. I spent a load of time figuring it out so that you don't have to.
Aight, I'll make this post a tl;dr and give references for further reading at the bottom.

Step #1

Update your tasks.json file (In case you don't know what that is, I suggest you head over here and then get back) with the following piece of code.

Alt Text

{"label": "Open Terminal",
"type": "shell",
"command": "osascript -e 'tell application \"Terminal\"\ndo script \"echo hello\"\nend tell'",
"problemMatcher": []
}

Now just run this task before running the c++ file, and in the launch.json, set


externalConsole: true

Your tasks.json should look something like this now.

Alt Text

Step #2

Now hit


cmd + shift + P

and type in ">run tasks" without the quotes of course.

And you should see something like this.

Alt Text

Click on


open terminal

and it launches a terminal. Smash the allow button once twice or as often as it asks and you're set.

Boom.

Alt Text

You'll have the terminal launched, and now when you run the actual g++-10 debug and run task, it should work fine.

Alt Text

See how the editor is in debug mode, and the terminal on the left is ready to accept input.
Hopefully this helped :)
In case you'd like to know more about this issue, head over here

Top comments (0)