‘g++’ is not recognized as an internal or external command, operable program or batch file

#include<iostream>
using namespace std;
int main()
{
    cout<<"hi"<<endl;   
    return 0;
}

I am using Sublime text 3, and I am getting this error:

error- ‘g++’ is not recognized as an internal or external command, operable program or batch file. [Finished in 0.0s]

4 Answers

For me, it’s easily fixed by two steps, as below:

  1. Set the environment variable:

    C:/MinGW/bin

  2. Paste the following code in the “launch.json”:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Compiler",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "C:/MinGW/bin",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true
        },
    ]
}

I installed a C++ compiler (MinGw). It resolved my issue while running .cpp from vsc editor. Follow this.

I faced the same problem while running the code from command line. And found out that I messed up with MinGW installation. So I reinstalled it,

Do this while installing MinGW —-

  1. After downloading, install MinGW and wait for the “MinGW Installation Manager” to show up.
  2. When the “MinGW Installation Manager” shows up, click on mingw32-gcc-g++ then select “Mark for Installation”
  3. In the menu at the top left corner, click on “Installation > Apply Changes”
  4. Wait and allow to install completely. Ensure you have a stable internet connection during this process.

when it is done, then edit the environment ‘Path’ Variable as stated in other answer.

In short I followed this

Leave a Reply

Your email address will not be published. Required fields are marked *