Galipan
Galipan

Reputation: 63

How do you include the C++ standard library in xcode 4.3

I'm trying to use C++ code in my ios app (I really don't like objective C, I'm going to use it only when necessary [view control, etc]) and while everything seems to be working I get an error in the following test file.

 #ifndef prueba3_GlobalStatic_h
 #define prueba3_GlobalStatic_h
 #include <string>

 using namespace std;

 class GlobalStatic
 {
 public:
     GlobalStatic();
     ~GlobalStatic();
     string foo();

 private:
     int integerValue;
 };

 #endif

When I try to build the project the IDE gives me the following error: " 'string' file not found" I've looked around but cannot find a conclusive answer; any help would be appreciated. In essence, how do I get the standard library working?

Upvotes: 2

Views: 4175

Answers (1)

robk
robk

Reputation: 78

One cause of missing c++ headers is including them from an objective-c context as opposed to from objective-c++ -- and you can't use the c++ stl from c! The easier solution is to simply change all your .m files to .mm, .mm will send them to the objective-c++ compiler.

Upvotes: 3

Related Questions