使用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()他只清除流的狀態標誌,不能清除流的內容。