如何返回局部变量。

渔樵者 2016-06-08 09:40:43
//打印json中的key值
if (*iter == "moreResults")
{ ////多种结果的返回
const Json::Value arrayObj = value["moreResults"]; //得到数组
for (unsigned int i = 0; i < 0/*arrayObj.size()*/; i++)
{
std::cout << i <<std::endl;
Json::Value test5;
//获取到了moreresult中的text文本
test5 = arrayObj[i]["answer"]["text"];
// std::cout <<test5<< std::endl;
char* temp;
std::string tem_more;
tem_more = test5.asString();
// temp = tem_more.c_str();
//string转char*
const int len = tem_more.length();
temp = new char[len+1];
strcpy(temp,tem_more.c_str());
return temp; //我想反悔temp_more,但是直接返回这局部变量就成乱码 ,只好new了一个,但是没有地方去delete了,不知道有没有什么好办法,各位高手给个提示吧
}
}
...全文
60 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
返回std::string 啊

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧