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()他只清除流的狀態標誌,不能清除流的內容。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章