Hello,
I have some gaps in the understanding of string::assign
method. Consider the following code:
char* c = new char[38];
strcpy(c, "All your base are belong to us!");
std::string s;
s.assign(c, 38);
Does s.assign
allocate a new buffer and copy the string into it or it assumes ownership of the pointer; i.e. doesn't allocate new memory and uses directly my address. If it copies, then what is the difference between assign
and operator=
? If it doesn't copy, then does it free the memory or it is my responsibility?
Thank you.