3

I have a new empty xcode project. It gives me "No such file or directory" compile error when I try to import some c++ libraries such as <iostream>, <string>, and <map>

What do I have to do to import c++ libraries into xcode for so I can call their functions in objective-c?

2
  • how about, click on the template Xcode offers you :P Commented Mar 1, 2011 at 0:09
  • 1
    You can't call C++ libraries in Objective-C. You can call them in Objective-C++... Commented Mar 1, 2011 at 0:11

1 Answer 1

3

If you are just trying to write C++ code in Xcode instead of calling C++ libraries in your objectiveC project you can create a C++ project. I just created a new project using the "Command Line Tool" template and selected C++ as the language.

I could then add the following lines without the compiler complaining.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

To use items from the std c++ libraries you prefix them with std::

int main (int argc, const char * argv[])
{
    std::cout << "Hello World!";

    return 0;
}

I was actually searching stack overflow for the reason std:: is necessary in Xcode...

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

1 Comment

at the top of your C++ file, simply add: using namespace std; and that should make it so that you do not need to use std:: on every file.

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.