在C++中更改常量std::字符串

Altering a const std::string in C++

本文关键字:std 字符串 常量 C++      更新时间:2023-10-16

我有一个常量std::字符串,我想将另一个字符串附加到该字符串。但由于它是恒定的,我不能直接改变它;我将不得不以某种方式将它复制到另一个字符串中。我该怎么做?

您只需要创建另一个字符串:

const std::string str = "Hello";
std::string other = str + ", world!";