分类: C/C++
2016-12-23 17:05:14
stirng 字符串拼接:
std::stringstream streamTmp; streamTmp << "test test test test ...."; //allMutedUserNodeId 为 std::vectorstd::vector ::iterator iter = allMutedUserNodeId.begin(); while(iter != allMutedUserNodeId.end()) { unsigned long dwMutedNodeId = *iter; streamTmp << dwMutedNodeId; streamTmp << ","; iter++; } //转换成string string jsonResultTmp = streamTmp.str();
string jsonResult (jsonResultTmp, 0, (jsonResultTmp.length() - 1));//不需要释放 jsonResult.append("end end end");
1. 强转
(char*)jsonResult.c_str()
char *cstr = new char[jsonResult.length() + 1]; strcpy(cstr, jsonResult.c_str()); //TBD do something.... delete[] cstr;//要删除,来源,