I would like to get the bytes a std::string‘s string occupies in memory, not the number of characters. The string contains a multibyte string. Would std::string::size() do this for me?
EDIT: Also, does size() also include the terminating NULL?
std::stringoperates on bytes, not on Unicode characters, sostd::string::size()will indeed return the size of the data in bytes (without the overhead thatstd::stringneeds to store the data, of course).No,
std::stringstores only the data you tell it to store (it does not need the trailingNULLcharacter). So it will not be included in the size, unless you explicitly create a string with a trailingNULLcharacter.