c++ vectorunsigned char 取前六个元素
可以使用vector的成员函数begin()和end()来获取迭代器,然后使用迭代器来访问元素。
下面是一个示例代码:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<unsigned char> vec = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
vector<unsigned char>::iterator it_begin = vec.begin();
vector<unsigned char>::iterator it_end = vec.begin() + 6;
for (auto it = it_begin; it != it_end; ++it) {
cout << static_cast<int>(*it) << " ";
}
cout << endl;
return 0;
}
输出结果为:
1 2 3 4 5 6
``
原文地址: https://www.cveoy.top/t/topic/e1jP 著作权归作者所有。请勿转载和采集!