我遇到了以下代码,它在我脑海中提出了一些问题
std::vector<unsigned char> buf(bytes.constData(), bytes.constData() + bytes.size());
在哪里 bytes is QByteArray
和bytes.constData()
返回const char*
我在这里查看了向量的构造函数,我认为适合此描述的唯一构造函数是
vector (InputIterator first, InputIterator last,
const allocator_type& alloc = allocator_type());
现在我的问题是:
1-是否可以将指针传递给向量的迭代器?为什么会这样bytes.constData() + bytes.size()
?例如,如果我们稍后对字节进行更改会影响 buf 吗?