C ++在字节向量和wstring之间转换 [英] C++ convert between Byte vector and wstring
本文介绍了C ++在字节向量和wstring之间转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要以低级别处理宽字符串中存储的数据。我可以使用以下方法转换
字节的
向量
:
I need to process the data stored in wide strings at a low level. I am able to convert to a vector
of Bytes
with the following method:
typedef unsigned char Byte;
wstring mystring = L"my wide string";
Byte const *pointer = reinterpret_cast<Byte const*>(&mystring[0]);
size_t size = mystring.size() * sizeof(mystring.front());
vector<Byte> byteVector(pointer, pointer + size);
但是,我遇到了麻烦,我对铸造不是很熟悉。如何将的
的
字节转换为
wstring
However, I am having trouble going the other way; I am not very familiar with casting. How do I convert a vector
of Bytes
to a wstring
?
推荐答案
您可以这样做
mystring.assign(reinterpret_cast< ; wstring :: const_pointer>(& byteVector [0]),byteVector.size()/ sizeof(wstring :: value_type));
这篇关于C ++在字节向量和wstring之间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文