什麼時候應該使用stringstream
而不是string::append()
? 假設我只是將字符串鏈接起來。什麼時候應該使用字符串而不是stringstream?
stringstream ss;
ss << str1 << "str2" << ...
Write(ss.str());
或者:
string str;
str.reserve(10000);
str.append(str1);
str.append("str2");
...
Write(str);
當中哪些是更快?