std::字符串串联操作

std::string concatenation operations

本文关键字:操作 字符串 std      更新时间:2023-10-16

实际上我想知道std::stringoperator+=append方法之间有什么不同。乍一看,他们解决了同样的问题。

在我的例子中,结果字符串是从不同的字符串编译而来的,这些函数中的哪一个更有效或更合适?还是应该使用std::stringstream

在我看来,std::stringstd::vector有很多共同点(capacityreserve和其他方法(,可以在追加操作期间重新分配。

好吧,标准说:

constexpr basic_string& operator+=(const basic_string& str);

效果:等效于:return append(str);

所以我想说他们完成了同样的事情。