String Character Length: Difference between revisions
Content deleted Content added
Fix C++ sizeof unicode |
|||
Line 105: | Line 105: | ||
{ |
{ |
||
std::string s = "Hello, world!"; |
std::string s = "Hello, world!"; |
||
// Always in characters == bytes since sizeof(char) == 1 |
|||
⚫ | |||
std::string::size_type |
std::string::size_type length = s.length(); // option 1: In Characters/Bytes |
||
⚫ | |||
} |
} |
||
Line 116: | Line 117: | ||
{ |
{ |
||
std::wstring s = L"\u304A\u306F\u3088\u3046"; |
std::wstring s = L"\u304A\u306F\u3088\u3046"; |
||
std::wstring::size_type length = s.length(); |
std::wstring::size_type length = s.length(); // In characters |
||
// Not equal since sizeof(wchar_t)==2 |
|||
} |
|||
std::wstring::size_type length = s.length() * sizeof(std::wstring::value_type); // In bytes |
|||
} |
|||
==[[C sharp|C#]]== |
==[[C sharp|C#]]== |