'iostream' file not found Xcode

Viewed 4342

Whenever I try to use Xcode 11 to build C++ programs and type in the line:

#include <iostream>

An error saying "'iostream' file not found shows up. The library I am using is libc++ and not libstdc++.

Other people dont seem to encounter this problem so I do not know what is going on.

#include <iostream>
using namespace std;

int main()
{
    cout << "Hey, this really works!" << endl;
}
5 Answers

We encountered the same problem while using a C++ class with Objective-C wrapper.

While checking the build command we found Xcode was passing objective-c as the language for clang. On changing the Wrapper file extension to '.mm', XCode started passing language as objective-c++ and the error was gone.

Try to add header file path:

Build Settings -> Search paths ->System Header Search Paths

add:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/

I was finally able to avoid this error, here's what I did.

  1. Open terminal and enter: xcode-select --install
  2. Use:
#include "/Library/Developer/CommandLineTools/usr/include/c++/v1/iostream"

instead of:

#include <iostream>

I ran in the terminal the following command:

xcode-select --install

At the end of the installation process, I quit and reopened Xcode, and the issue was gone.

I encountered exactly the same problem. A lot of people did actually. I've tried reinstalling Xcode, but the error persisted. The only thing that helped is to update everything with brew update.

Related