How to Run cpp files in vscode on Mac

How to Run cpp files in vscode on Mac

Table of contents

No heading

No headings in the article.

Download and install a C++ compiler:

  1. Install macPorts

  2. Install mingw for mac by running the below command after installing the macPorts from above (ports.macports.org/port/mingw-w64)

sudo port install mingw-w64

This will take around 10mins depending upon your net speed

  1. Add the mingw installation path in your PATH variable

Check your current PATH first

echo $PATH
  1. Append the mingw installation path in your existing PATH variable

export PATH=“\bin:$PATH”

  1. Install Code Runner extension in VS Code

  2. After installing restart VsCode. Open your C++ file in VsCode.

  3. If you do not do this step then all logs would be seen in output window. If you want to see it in terminal then follow below steps

  • In VsCode, Go to Code > Preference > Setting.

  • In the User tab on the left panel, find the extensions section

  • Scroll and find ‘Run Code Configuration’

  • Scroll and find a checkbox "Run in Terminal"

  1. Close the terminal & relaunch. You can click the play button on top right of the editor for running the code

    Screenshot 2022-09-05 at 12.22.02 AM.png

Tadaa!! Your cpp file is running successfully on vs code

Feel free to connect on twitter, linkedin