什么时候应该使用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);
当中哪些是更快?