C ++ UTF-8实际字符串长度 [英] C++ UTF-8 actual string length
问题描述
在任何标准库中都有任何原生(跨平台) C ++
函数返回 std :: string
?
更新:
我们知道 std :: string.length
返回字节数而不是字符数。
我已经有一个自定义函数返回实际的函数,但我正在寻找一个标准的函数。
codecvt
应该是有用的,标准提供了UTF-8的实现,例如 codecvt_utf8< char32_t>()
可能是这样:
wstring_convert< codecvt_utf8< char32_t>,char32_t>()。from_bytes(the_std_string).size()
Is there any native (cross platform) C++
function in any of standard libraries which returns the actual length of std::string
?
Update:
as we know std::string.length()
returns the number of bytes not the number of characters.
I already have a custom function which returns the actual one, but I'm looking for an standard one.
codecvt
ought to be helpful, the Standard provides implementations for UTF-8, for example codecvt_utf8<char32_t>()
would be appropriate in this case.
Probably something like:
wstring_convert< codecvt_utf8<char32_t>, char32_t >().from_bytes(the_std_string).size()
这篇关于C ++ UTF-8实际字符串长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!