C++11 char16_t strlen-equivalent function

自作多情 提交于 2019-12-10 02:09:31

问题


I have a simple question: Is there a way to do a strlen()-like count of characters in zero-terminated char16_t array?


回答1:


use

char_traits<char16_t>::length(your_pointer)

see 21.2.3.2 struct char_traits<char16_t> and table 62 of the C++11-Std.




回答2:


Use pointers :), create a duplicate pointer to the start, then loop through it while (*endptr++);, then the length is given by endptr - startptr. You can actually template this, however, its possible the the compile won't generate the same intrinsic code it does for strlen(for different sizes ofc).



来源:https://stackoverflow.com/questions/5818508/c11-char16-t-strlen-equivalent-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!