C++ 如何将std::string转换为NSString?

C++ 如何将std::string转换为NSString?,c++,ios,objective-c,nsstring,C++,Ios,Objective C,Nsstring,您可以从图片中读取代码。函数getResult()返回一个std::字符串,如“启 动 照相机 \n-4.93”,但结果是乱码,NSStringres是零。 我使用lldb命令po,找到\u数据,它是什么?为什么NSStringres为零 这是导致问题的代码: std:string result = getResult(); NSString *res = [NSString stringWithCString:result.c_str() encoding:NSUTF8String

您可以从图片中读取代码。函数
getResult()
返回一个std::字符串,如“
启 动   照相机   \n-4.93
”,但
结果
是乱码,NSString
res
是零。 我使用lldb命令
po
,找到
\u数据,它是什么?为什么NSString
res
为零

这是导致问题的代码:

std:string result = getResult();

NSString *res = [NSString stringWithCString:result.c_str() encoding:NSUTF8StringEncoding];
这是
getResult
功能代码:

std::string getResult()
{
    char *res = NULL;

    asGetResult(&res);

    if (res != NULL) {

     printf("asGetResult = %s \n",res);
     return std::string(res);
    }
   else
   {
     return std::string("");
   }
}


<函数>函数>代码> GETRESUT/CODE>包含在静态库中,它是用C++编写的。< /P> <代码> GETREST < /代码>是什么样子的?(发布文本,而不是截图。)我已经编写了
getResult
函数。你能解释一下原因吗?你的字符串使用什么字符编码?如果使用了care,并且您知道自己的编码,
std::string
可以与Unicode一起使用,但它很混乱可以打印
启 动   照相机   \n-4.93
每次。