std :: string is the underlying char array.
Std :: string when making an assignment, not a new piece of memory, but the memory of the newly created object reference the same char *. Wait until you need to modify the object of the time, and then copy it.
The following functions will trigger copy on write:
- reverse()
- resize()
- []
- assign
std :: string contains a reference count, a new copy of the object will only increase when the reference count. When the reference count is not 1, it means not exclusively, copy, re-apply for a new memory char array.