如何获得 std::wstring 的字节大小? [英] How can I get the byte size of std::wstring?

查看:57
本文介绍了如何获得 std::wstring 的字节大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 std::wstring 作为我的 Unicode 样式字符串.现在我想得到wstring 的字节大小.如果我使用 wstringsize() 方法,我只会得到字符的总数在我的 wstring 中.但是字节应该是 size() * 2.有没有官方的方法来获得这个字节大小?我不想使用size() * 2 在我的程序中.....

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.....

我想在 RegSetValueExW 中使用作为最后一个参数.

I want to use in RegSetValueExW as last parameter.

推荐答案

使用 str.size() * sizeof(wchar_t) 或等价物.

事实上,除了 Windows 之外,我想不出任何其他平台有 2 字节的 wchar_t,4 字节更为常见.

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

这篇关于如何获得 std::wstring 的字节大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆