[英]std::string concatenation operations
Actually I wondered what different between std::string
operator+=
and append
methods.实际上我想知道
std::string
operator+=
和append
方法有什么不同。 In first glance they solve the same problem.乍一看,他们解决了同样的问题。
In my case resulted string was compiled from different strings, and which of these functions more effective or appropriate?在我的情况下,结果字符串是从不同的字符串编译的,这些函数中哪个更有效或更合适? Or should I use
std::stringstream
instead?或者我应该改用
std::stringstream
吗?
How I see, std::string
has a lot in common with std::vector
( capacity
, reserve
and other methods) and can be reallocated during the appending operation.我怎么看,
std::string
与std::vector
( capacity
, reserve
和其他方法)有很多共同点,并且可以在附加操作期间重新分配。
Well, the standard says:好吧,标准说:
constexpr basic_string& operator+=(const basic_string& str);
Effects: Equivalent to:
return append(str);
效果:相当于:
return append(str);
So I would say that they accomplish the same thing.所以我会说他们完成了同样的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.