Constructing a new std::string via a const char* makes less sense in cases where a substring ctor (or equivalent assign()) can be used. It means iterating thru the string once to find the null terminator (strlen) to know how much memory to allocate, then again to copy. Why do that when we can take advantage of std::string::size()?
...Right? Test this theory in practice. Call std::string::capacity()...
Constructing a new
std::string
via aconst char*
makes less sense in cases where a substring ctor (or equivalentassign()
) can be used. It means iterating thru the string once to find the null terminator (strlen
) to know how much memory to allocate, then again to copy. Why do that when we can take advantage ofstd::string::size()
?Call std::string::capacity()
...const char*