stirng 字符串拼接:
std::stringstream streamTmp;
streamTmp << "test test test test ....";
//allMutedUserNodeId 为 std::vector<unsigned long>
std::vector<unsigned long>::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");
const char* 转 char*
1. 强转
(char*)jsonResult.c_str()
2. 字符拷贝
char *cstr = new char[jsonResult.length() + 1];
strcpy(cstr, jsonResult.c_str());
//TBD do something....
delete[] cstr;//要删除