c++若sizeof(wchar_t)=4的话,怎么求宽字符串的字符数目呢

2025-02-22 22:35:17
推荐回答(4个)
回答1:

法一:用stl的basic_string模板类
#include
std::basic_string wcstr;
wchar_t wcs[] = {1, 2, 3, 4, 0};

wcstr = wcs;

size_t len = wcstr.length();

法二:自写求长度函数,for循环判断最后一个wchar_t是0即可。

回答2:

1、用stl的basic_string模板类
#include
std::basic_string wcstr;
wchar_t wcs[] = {1, 2, 3, 4, 0};
wcstr = wcs;
size_t len = wcstr.length();

2、自己写求长度函数,for循环判断最后一个wchar_t是0即可。

回答3:

当你的工程用的字符集是宽字符集的时候,你所有用char的地方就要改成wchar_t。比如unicode。

回答4:

wchar_t a[20];
int b=sizeof(a)/sizeof(a[0]);