7

I am using VSCode and the code compiles just fine with the .run extension but the C/C++ extension is throwing me this error and underlining #include <iostream> as an error. And yes I have MinGW installed in my system.

Furthermore, I get the same error on visual studio community 2019, it does not execute there at all.

System: Windows 10 Version 10.0.19042 Build 19042

VSCode Version: 1.54.1

gcc version: 8.1.0

Visual Studio Community Version: 16.8.5 (Just used it to check if the problem was due to VSCode or if it was a systematic error)

Extension Showing the error: C/C++ for Visual Studio Code v1.2.2

The extension I use to run the code: Code Runner v0.11.3

UmiKami
  • 121
  • 1
  • 8
  • Please update you question with your env. e.g. Windows, VSCode version, Extension and extension version, etc. – J'e Mar 11 '21 at 15:49
  • @J'e done! It sounds like a systematic error but beyond that, I have no idea of what is causing it. – UmiKami Mar 11 '21 at 16:04
  • 2
    Does this answer your question? [Visual Studio Code includePath](https://stackoverflow.com/questions/37522462/visual-studio-code-includepath) – J'e Mar 11 '21 at 16:20
  • Check if you have this path or similar: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\iostream` Ctrl + Click in the iostream to open (if it exists) – testing_22 Mar 11 '21 at 16:25
  • You probably need to update the windows SDK in your visual studio community install. – drescherjm Mar 11 '21 at 16:30
  • ***And yes I have MinGW installed in my system.*** Which compiler are you using in VSCode. I expect each will have its own independent headers. – drescherjm Mar 11 '21 at 16:36
  • ***I have no idea of what is causing it*** Could be a misconfigured `c_cpp_properties.json` – drescherjm Mar 11 '21 at 16:37
  • Thanks, everyone! @J'e solution worked. I had to include the "include" directory from the MinGW folder. The error still jumps on previously created projects but it doesn't on new ones. – UmiKami Mar 11 '21 at 16:53
  • Update: It seems like it solved itself and idk how... Before I tried creating multiple files to see if it was a project dependant error. It was not, it was giving the same error in every new project. Now all of the sudden created a .cpp file manually and no errors jumped. So weird... – UmiKami Mar 11 '21 at 17:01
  • @drescherjm According to the c_cpp_properties.json the compiler is the MSVC compiler. – UmiKami Mar 11 '21 at 17:03

4 Answers4

8
  • hover on the line showing error
  • left click on the bulb, it will take you to C/C++ configurations
  • Now change complier path to C:/MinGW64/bin/g++.exe
  • on the top u will see a link c_cpp_properties.json click on it
  • in c_cpp_properties.json "intelliSenseMode": "windows-gcc-x64"

This works well.

0

2022 UPDATE:

answer by @Prabhat Bhargav worked for me, but I had to change path to C:/MinGW/bin/g++.exe instead of C:/MinGW64/bin/g++.exe

Guess they changed default folder name by removing 64 (at least on windows 10).

After that it worked properly. Also if you changed the default installation folder when installing MinGW compiler, you will have to select that as your compiler path.

0

click on include path settings. Edit your compiler path and set it to MINGW gcc.

it will solve your problem.

0
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/msys64/mingw64/x86_64-w64-mingw32/bin"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:/msys64/mingw64/bin/g++.exe",
            "cStandard": "gnu17",
            "cppStandard": "c++23",
            "intelliSenseMode": "${default}",
            "configurationProvider": "ms-vscode-cpptools"
        }
    ],
    "version": 4
}
ayoub Cyb
  • 41
  • 3