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

时间:2014-11-20 12:54:03

标签: c++ ios objective-c nsstring

你可以从图片中读取代码。函数getResult()返回一个std :: string,就像&#34; <s> 启 动 <unk> <_Apps_> 照相机 </_Apps_> </s> \n-4.93&#34;,但result是乱码,NSString res为零。 我使用lldb命令po,找到_data,它是什么?为什么NSString res为零。

enter image description here

这是导致问题的代码:

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("");
   }

}

函数getResult包含在静态库中,由c ++编写。

0 个答案:

没有答案