std::string, NSString, const char * 互转

https://stackoverflow.com/questions/3552195/how-to-convert-stdstring-to-nsstring

1. std::string 或 const char * 转 NSString

std::string stdString = "";

NSString *ocString = [NSString stringWithCString:stdString.c_str() encoding:[NSString defaultCStringEncoding]];

const char *cString = "";

NSString *ocString = [NSString stringWithCString:cString encoding:[NSString defaultCStringEncoding]];

2. NSString 转 std::string 或 const char *

NSString *ocString = @"";

std::string stdString = [ocString UTF8String];

const char *cString = [ocString UTF8String];

你可能感兴趣的:(std::string, NSString, const char * 互转)