const char* Fun(char* arg)
{
std::string res = Cal(arg);
//return res.data();
//改为以下代码后正常:
char *result = new char[res.length() + 1]; //定义需要返回的result对象
for (int i = 0; i < res.length(); ++i)
{
result[i] = res[i]; //将string类型的res内容都放到result内
}
result[res.length()] = '\0'; //加上结束符
return result;
}
C++将string转为char*类型作为返回值乱码问题解决
于 2022-09-14 16:24:13 首次发布