get length of `wchar_t*` in c++

后端 未结 2 1524
遥遥无期
遥遥无期 2021-02-05 02:00

Please, how can I find out the length of a variable of type wchar_t* in c++?

code example below:

wchar_t* dimObjPrefix = L\"retro_\";


        
相关标签:
2条回答
  • 2021-02-05 02:33

    If you want to know the size of a wchar_t string (wchar_t *), you want to use wcslen(3):

    size_t wcslen (const wchar_t *ws);
    
    0 讨论(0)
  • 2021-02-05 02:42

    Assuming that you want to get the length of null terminated C style string, you have two options:

    1. #include <cwchar> and use std::wcslen (dimObjPrefix);,
    2. or #include <string> and use std::char_traits<wchar_t>::length (dimObjPrefix);.
    0 讨论(0)
提交回复
热议问题