c++macosvisual-studio-codecomputer-scienceinclude-path

Visual Studio Code cannot open source file "iostream"


I am new to C++ and Visual Studio Code, so I'm not sure how to fix this issue. I've tried to go through the tutorial in Using Clang in Visual Studio Code, but I can't seem to paste their "Hello, World!" code without the iostream, vector, and string errors.

I've also seen posts on here indicating that I should change the includePath string array in configurations, but adding the path to my project folder doesn't seem to get rid of these errors. I'm at a loss here since everything I've seen so far still isn't working.

The code which causes these errors has been copy pasted directly from the tutorial above:

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};

    for (const string& word : msg)
    {
        cout << word << " ";
    }
    cout << endl;
}

In the first three lines, I'm getting the errors "cannot open source file {the included import's name}". The compiler states that:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/Users/rjc/projects/helloworld/helloworld.cpp).C/C++(1696)

I added this line in my includePath as such (the configurations page states add one includePath per line, so I put these two statements on separate lines):

${workspaceFolder}/** /Users/rjc/projects/helloworld/

Yet this did not reduce the number of errors. I'm not really sure what to do here, since the tutorial does not seem to be working for me.

I'm running macOS 11.1 (Big Sur) with Clang version 12.0.0. Why do I have these issues?


Solution

  • Your includePath only has ${workspaceFolder}. You need to add the path to your system directory. Run this command and make sure all of the paths printed out are listed in your c_cpp_properties.json file: gcc -v -E -x c++ -