public member function
<string>
std::string::size
size_t size() const noexcept;
Return length of string
This is the number of actual bytes that conform the contents of the string, which is not necessarily equal to its storage capacity.
Note that string objects handle bytes without knowledge of the encoding that may eventually be used to encode the characters it contains. Therefore, the value returned may not correspond to the actual number of encoded characters in sequences of multi-byte or variable-length characters (such as UTF-8).
Both
string::size and string::length are synonyms and return the same value.Parameters
noneReturn Value
The number of bytes in the string.size_t is an unsigned integral type (the same as member type string::size_type).
Example
|
|
Output:
The size of str is 11 bytes
Complexity
Iterator validity
No changes.Data races
The object is accessed.Exception safety
No-throw guarantee: this member function never throws exceptions.See also
- string::length
- Return length of string (public member function)
- string::resize
- Resize string (public member function)
- string::max_size
- Return maximum size of string (public member function)
- string::capacity
- Return size of allocated storage (public member function)