美文网首页
std::string, NSString, const cha

std::string, NSString, const cha

作者: llyihh | 来源:发表于2017-12-19 10:54 被阅读0次

    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 cha

          本文链接:https://www.haomeiwen.com/subject/gxlbwxtx.html