In particular, how do the code check if memory for chars should be reallocated? Or how many chars the user entered? If I wanted to assign a C-string's value to my implementation of a string class I would probably do something like this
String& operator=(String& to, const char *from)
{
if((strlen(from) + 1) > to.size) {
if (to.str != NULL) {
delete[] to.str;
to.str = NULL;
}
to.size = strlen(from) + 1;
to.str = new char[to.size];
}
strcpy(to.str, from);
return to;
}
Easy enough. But the operator>> of the std::string is really making me curious.