C ++ STL的字符串eqivalent的二进制数据 [英] C++ STL's String eqivalent for Binary Data
问题描述
我写一个C ++应用程序,我想知道什么C ++在内存中存储的字节数组的传统方式。
I am writing a C++ application and I was wondering what the C++ conventional way of storing a byte array in memory.
有什么样的字符串,除了专门为二进制数据的。
Is there something like a string, except specifically made for binary data.
现在我使用的是*无符号字符数组**来存储数据,但更多的东西STL / C ++一样会更好。
Right now I am using a *unsigned char** array to store the data, but something more STL/C++ like would be better.
推荐答案
我会使用的std ::矢量< unsigned char型>
。你最需要的操作都可以使用与迭代范围内的STL来完成。此外,请记住,如果你真的需要的原始数据&放大器; v [0]
肯定能给一个指向底层数组
I'd use std::vector<unsigned char>
. Most operations you need can be done using the STL with iterator ranges. Also, remember that if you really need the raw data &v[0]
is guaranteed to give a pointer to the underlying array.
这篇关于C ++ STL的字符串eqivalent的二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!