gpt4 book ai didi

c++ - 使用 std::copy 复制到 std::deque

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:26:01 32 4
gpt4 key购买 nike

我有一个 C 风格的数组 unsigned char Temp[SERVER_BUFFER_SIZE] 并且我想将它复制到一个 std::deque 最后(更像是追加它)

std::deque<unsigned char>* buffer = new std::deque<unsigned char>();
std::copy(Temp[0], Temp[SERVER_BUFFER_SIZE], buffer->cend());

我遇到了很多这样的错误:

Error 4 error C2825: '_Iter': must be a class or namespace when followed by '::' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility 371 1 a Error 5 error C2039: 'iterator_category' : is not a member of '`global namespace'' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility 371 1 a Error 9 error C2825: '_Iter': must be a class or namespace when followed by '::' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility 372 1 a Error 12 error C2602: 'std::iterator_traits<_InIt>::value_type' is not a member of a base class of 'std::iterator_traits<_InIt>' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility 372 1 a

最佳答案

Error 告诉你做错了什么。 std::copy 接受迭代器,而你给它的是字符。 Temp[0]Temp[SERVER_BUFFER_SIZE] 只是 unsigned char

但是你不需要std::copydeque本身有一个双迭代器构造函数:

std::deque<unsigned char>* buffer = new std::deque<unsigned char>(Temp, 
Temp + SERVER_BUFFER_SIZE);

或者只是:

std::deque<unsigned char> buffer(Temp, Temp + SERVER_BUFFER_SIZE);

关于c++ - 使用 std::copy 复制到 std::deque,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26819211/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com