繁体   English   中英

如何将此数组转换为向量?

[英]How do I convert this array to a vector?

const int NUM_DIGITS = 7;
int pin1[NUM_DIGITS] = {2, 4, 1, 8, 7, 9, 0};
int pin2[NUM_DIGITS] = {2, 4, 6, 8, 7, 9, 0};
int pin3[NUM_DIGITS] = {1, 2, 3, 4, 5, 6, 7};

std :: vector定义了一个构造函数,该构造函数接受两个InputIterators和一个默认分配器,并带有

template <class InputIterator>
     vector (InputIterator first, InputIterator last,
             const allocator_type& alloc = allocator_type());

因此,您可以像这样从数组创建向量,

std::vector<int> vec(pin1, pin1 + NUM_DIGITS);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM