【发布时间】:2013-01-14 17:41:48
【问题描述】:
您好,我想了解为什么以下代码不起作用。我正在尝试使用指针作为 std::copy 算法的输入迭代器类型。 fsRead.Buffer 指向我要复制的数据的开头,fsRead.BufferSize 是我们要复制的数据的大小。
// AllocateZeroPool(UINT64) takes an input size, and returns a pointer to allocated memory. (this is the existing C api)
fsRead.Buffer = static_cast<UINT8*>(AllocateZeroPool(fsRead.BufferSize));
//
// this next line populates the data into fsRead.Buffer
auto status = mFs->read_data(nullptr, &fsRead);
the type of file.data is: std::vector<UINT8>
std::copy(fsRead.Buffer, fsRead.Buffer + fsRead.BufferSize, file.data.begin());
file.data.size() 在上述 std::copy() 调用中为零。
为了将数据放入vector file.data,我目前是手动复制的:
for(auto i(0U); i < fsRead.BufferSize; ++i) {
file.mBinaryData.emplace_back(fsRead.Buffer[i]);
}
为什么使用两个指针作为输入迭代器似乎不起作用?
编辑:澄清一下,我的意思是实际上没有数据被复制到 file.mBinaryData 向量中。
【问题讨论】:
-
它“似乎不起作用”是什么意思?请描述错误...
标签: c++ vector iterator copy std