5

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;
}
2
  • 1
    Is this a C or C++ project? What's the filename? Did you try to compile it in terminal with g++ FILE.cpp? Commented Oct 3, 2019 at 22:05
  • @ThomasSablik It is a C++ project and the filename is "abc.cpp". Yes, I tried running it in the terminal and it gave me no error. I compiled and executed the code on Xcode itself and it runs just fine, but the error doesn't seem to budge. Commented Oct 4, 2019 at 16:39

7 Answers 7

5

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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/

1 Comment

Whomever you are good sir this is the absolute fix!!! thank you!!!!!!!!!
2

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>

Comments

1

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.

1 Comment

Tried it on a lark as Xcode "system header search paths" seems broken. No joy through any side effect of installing, "system header search paths" still broken.
0

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.

Comments

0

If you are still stuck after trying all the suggestions mentioned above(as I was :D), try these two commands, it worked for me:

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

First command removes all the contents/packages for CommandLineTools in Xcode package.

Second command reinstalls it.

Comments

0

If you are experiencing this issue ('iostream' file not found or 'string' file not found or 'map' file not found) while building a macOS "Framework" in Xcode which contains C++ source files, try the following:

Select the Target for your Framework. Click on the "Build Settings" tab and search for "Defines Module". Turn this option to NO. That should fix the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.