1

I'm trying to compile C++ files in Visual Studio Code How to use C/Cpp extension and add includepath to configurations but I'm getting this errors:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit.
cannot open source file "iostream"

I already saw this question and any of the solutions worked for me. Also I recorded a video following the steps of the visual studio code tutorial. Here is my code:

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello World" << endl;
}

And this are my C/C++ settings:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\x86_64-w64-mingw32\\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "${default}"
        }
    ],
    "version": 4
}

2 Answers2

2

open command pallete (ctrl + shift + P) then search edit configuration , select C/C++ edit configuration(UI) . Then scroll down and you will see include path , copy the location of your include path by finding it in file manager , By default the location would be C:\Program Files(x86)\mingw-w64\......\mingw32\include. Set intellisense to default. Now you are ready to enjoy your coding journey.

bug_29
  • 318
  • 2
  • 13
0

If you got this problem, Relax, u r probablu 1000th one here ;) I have added screenshots, these are not links to some terrifying third party documentations (;

Solution

1.installation of c++ : check you have the c++ installed, (it dosent come pre-installed! You have to do it) If not install it. If you have installed it, navigate to it, and get the path click on the path at top in file explorer, and Ctrl+C to copy it here is how u get the path

2.path environment variable setup steps: i.left click This pc(in file explorer)here

ii. manage this menu will open

iii. scroll down in the about section, find "Advanced System Settings" and follow along this

V. "edit environment variable" dialogue box will open, click new, then paste the link to the gcc compiler that you installed firstly.

Now, this path is set as environment variable, try running command : gcc --version in command panel, if still there is error, try uploading different paths of gcc.exe to the environment variable "Path". Also, re-starting pc is recommended if path variable change doesn't appear.

Now we start(or restart if it was open) the Vs-code(just a little to go) i. Shift+Ctrl+p then : follow this

ii.then this if the dropdown dosnt show any option, try re-starting vs-code, or pc, re-setting the environment variable step, or re-installing c++ and starting over(in worst case) iii.scroll down the same page, and paste the path to include folders from c++ to text box corrosponding to "Include path" . you have to first get this path, search for folder with name "include", copy and add its path.(many times, ide is capable to automate this step;))

Now try running the code, it must be good to go, but iff it still throws error, try repeating process of adding environment variable, re-staqrting vscode, or even then, re-installing c++.

Shubham
  • 3
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 17 '22 at 17:04