在 C++ 中获取 `wchar_t*` 的长度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2853615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:17:32 来源:igfitidea点击:
get length of `wchar_t*` in c++
提问by Jacob
Please, how can I find out the length of a variable of type wchar_t*
in c++?
请问,我怎样才能找出wchar_t*
C++中类型变量的长度?
code example below:
下面的代码示例:
wchar_t* dimObjPrefix = L"retro_";
I would like to find out how many characters dimObjPrefix
contains
我想知道dimObjPrefix
包含多少个字符
回答by Bertrand Marron
回答by wilx
Assuming that you want to get the length of null terminated C style string, you have two options:
假设您要获取空终止 C 样式字符串的长度,您有两个选择:
#include <cwchar>
and usestd::wcslen (dimObjPrefix);
,- or
#include <string>
and usestd::char_traits<wchar_t>::length (dimObjPrefix);
.
#include <cwchar>
并使用std::wcslen (dimObjPrefix);
,- 或
#include <string>
并使用std::char_traits<wchar_t>::length (dimObjPrefix);
.