2016-03-07 47 views
0
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}; 
+0

哪一種,有其中三個。另外,你還試過什麼。 –

回答

1

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); 
+1

很好的答案。另外值得注意的是,如果陣列版本不需要任何東西,你可以只構建一個向量,例如pin = {2,4,1,8,7,9,0};' '是可選的)。 –