vscode cannot open source file "iostream"

22,100

Your includePath only have ${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: gcc -v -E -x c++ -

Share:
22,100
rjc810
Author by

rjc810

Updated on July 05, 2022

Comments

  • rjc810
    rjc810 almost 2 years

    I am new to c++ and vscode, so I'm not sure how to fix this issue. I've tried to go through the tutorial at https://code.visualstudio.com/docs/cpp/config-clang-mac 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 Big Sur (11.1) with clang version 12.0.0. Would be grateful for any intuition as to why I'm having these issues.