What is the result of std::wstring.length() function, the length in wchar_t(s) or the length in symbols? And why?
TCHAR r2[3];
r2[0] = 0xD834; // D834, DD1E - musical G clef
r2[1] = 0xDD1E; //
r2[2] = 0x0000; // '/0'
std::wstring r = r2;
std::cout << "capacity: " << r.capacity() << std::endl;
std::cout << "length: " << r.length() << std::endl;
std::cout << "size: " << r.size() << std::endl;
std::cout << "max_size: " << r.max_size() << std::endl;
Output>
capacity: 351
length: 2
size: 2
max_size: 2147483646
std::wstring::size()returns the number of wide-char elements in the string. This is not the same as the number of characters (as you correctly noticed).Unfortunately, the
std::basic_stringtemplate (and thus its instantiations, such asstd::stringandstd::wstring) is encoding-agnostic. In this sense, it is actually just a template for a string of bytes and not a string of characters.