views:

90

answers:

1

Hi I am trying to convert a standard std::string into a NSString but i'm not having much luck

I can convert successfully from an NSString to a std::string with the following code

NSString *realm = "Hollywood";
std::string REALM = [realm cStringUsingEncoding:[NSString defaultCStringEncoding]];

However i get a compile time error when i try the following

NSString *errorMessage = [NSString stringWithCString:REALM encoding:[NSString defaultCStringEncoding]];

The error i get is

Cannot convert 'std::string' to 'const char*' in argument passing

Am i missing something here?

Thanks in advance.

+3  A: 

Get c-string out of std::string for conversion:

NSString *errorMessage = [NSString stringWithCString:REALM.c_str() 
                                   encoding:[NSString defaultCStringEncoding]];
Vladimir