Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the byte size of std::wstring?

I am using std::wstring as my Unicode style string. Now I want to get the byte size of a wstring. If I use size() method of wstring, I just get the total number of chars in my wstring. But the byte should be size() * 2. Is there an official way to get this byte size? I don't want to use size() * 2 in my program.....

I want to use in RegSetValueExW as last parameter.

like image 339
Hooch Avatar asked Feb 14 '12 14:02

Hooch


1 Answers

Use str.size() * sizeof(wchar_t) or equivalent.

In fact, I can't think of any other platform besides Windows that has 2-byte wchar_t, 4 bytes is far more common.

like image 141
Dietrich Epp Avatar answered Sep 23 '22 16:09

Dietrich Epp