Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get length of `wchar_t*` in c++

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

like image 740
Jacob Avatar asked May 17 '10 23:05

Jacob


2 Answers

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);
like image 111
Bertrand Marron Avatar answered Oct 21 '22 03:10

Bertrand Marron


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);.
like image 42
wilx Avatar answered Oct 21 '22 01:10

wilx