#include <iostream>
#include <string>
using namespace std;
int main () {
string str = "Hello";
str = "Hello World";
cout<<str<<endl;
}
字符串是如何处理内存的?
最佳答案
回复:
” How is the memory handled by the string?
自动地。
除其他事项外,这意味着无法为 std::string
提供一个外部创建的缓冲区。所以效率有点低。从好的方面来说,std::string
(相对于 std::vector
)的 swap
要求意味着它可以使用 < strong>小缓冲区优化,短字符串存储,无需动态分配,有助于提高效率。
关于c++ - 当我们在 C++ 中更改字符串的值时会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41531152/