ostringstream用法

使用MFC都知道他有一个非常方便的字符串类CString,C++标准也有一个string类,但是处理起来不够灵活,特别是没有类似Format()的函数。

 

无意中看到ostringstream的用法,使用它可以达到类似的效果。

 

ostringstream os;

string str = “abcef”;

int i = 1000;

os << str << i;

std::cout << os.str();//输出”abcef1000″

os.str(“”);//清空

//os.clear()他只清除流的状态标志,不能清除流的内容。

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注