问题
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_";
I would like to find out how many characters dimObjPrefix
contains
回答1:
sizeof (wchar_t);
Edit:
I just noticed the string
tag. 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);
回答2:
Assuming that you want to get the length of null terminated C style string, you have two options:
#include <cwchar>
and usestd::wcslen (dimObjPrefix);
,- or
#include <string>
and usestd::char_traits<wchar_t>::length (dimObjPrefix);
.
来源:https://stackoverflow.com/questions/2853615/get-length-of-wchar-t-in-c