Convert from string to NSString


I am having the error:
No viable conversion from ‘string’ (aka ‘basic_string’) to ‘NSString *’

How do I do this conversion?


You just need to use the C-style string contained within a std::string:

NSString *objcString = [NSString stringWithCString:cppString.c_str()   
                                   encoding:[NSString defaultCStringEncoding]];  

1 Like

Works like a charm. Thank you.

Would you be able to direct me to any documentation about conversions like this?

Generally I just check stackoverflow for stuff like that, a little more high-level article I remember finding helpful was this:±and-objective-c++ but there’s a lot of weirdness like how to work with NSDictionary and other ObjC types that it’s best to just look around SO to find answers on.