It's not obvious from cppref's description on capacity()
and reserve()
whether terminating null character is counted.
The standard states that:
In all cases,
size() <= capacity()
.
And size()
does not include the terminating null.
Since it is possible that size()
equals capacity()
, in that case it would mean that capacity()
also does not count the terminating null.
Note that in C++11 and later, mystring.c_str()
is equivalent to mystring.data()
is equivalent to &mystring[0]
, and mystring[mystring.size()]
is guaranteed to be '\0'
.
Check this Demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With