Dmitry Denisenkov said:
Hi,
I recently found out that in std::string a("some text"),
a.length()==a.size().
That's by design.
----------------------------------------------------------------------------
-----
ISO/IEC 14882:1998(E)
21.3.3 basic_string capacity
size_type size() const;
1 Returns: a count of the number of char-like objects currently in the
string.
size_type length() const;
2 Returns: size().
----------------------------------------------------------------------------
-----
Does that mean that c++ strings are, unlike c strings,
NOT terminated by char(0)?
It has nothing to do with a 'terminator'. It just means that both
functions return the same value for the same string.
For some reason I used to think that they are.
No, std::string type does not use a terminator for length determination
as does a 'C style string'. The length (aka size) of a std::string
is reported by the above member functions.
A std::string can contain any character values at all, including
ones with a value of zero.
std::string s(10, 0); /* construct a string containing ten characters, */
/* all of whose value is zero */
std:: cout << s.size() << '\n'; /* prints 10 */
-Mike