Chinaunix首页 | 论坛 | 博客
  • 博客访问: 265582
  • 博文数量: 81
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 878
  • 用 户 组: 普通用户
  • 注册时间: 2014-07-25 23:20
文章分类

全部博文(81)

文章存档

2017年(45)

2016年(20)

2015年(2)

2014年(14)

我的朋友

分类: C/C++

2016-12-23 17:05:14

stirng 字符串拼接:

std::stringstream streamTmp;
streamTmp << "test test test test ....";
//allMutedUserNodeId 为 std::vector
std::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");

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;//要删除,来源,
阅读(1532) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~