ostringstream用法

来源:互联网 发布:mac装linux虚拟机 编辑:程序博客网 时间:2024/04/29 17:13

使用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()他只清除流的状态标志,不能清除流的内容。