Since C ++ is compatible with C, C ++ maintainsProgram, May encounter an array written in C, but C ++'s STD: vector is far better than array, so it may have to convert the array to STD: vector for further maintenance, the following program demo converts an array to STD: vector.
1 /**/ /*
2 (C) oomusou 2006 Http://oomusou.cnblogs.com
3
4 Filename: arraytovectorbyconstructor. cpp
5 Compiler: Visual C + + 8.0
6 Description: Demo how to convert array to vector by vector Constructor
7 Release: 11/15/2006 1.0
8 12/10/2006 2.0
9 */
10 # Include < Iostream >
11 # Include < Vector >
12 # Include < Algorithm >
13
14 Using Namespace STD;
15
16 Int Main () {
17 // Const int iasize = 11;
18 Int IA [] = { 0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 55 , 89 } ;
19
20 // We specify the address of the first element
21 // The array as 1st argument, and the address
22 // One past the last element as 2nd argument.
23 Vector < Int > Ivec (IA, IA + Sizeof (Ia) / Sizeof ( Int ));
24 Copy (ivec. Begin (), ivec. End (), ostream_iterator < Int > (Cout, " \ N " ));
25
26 Return 0 ;
27 }
See also
(Original partition) how to convert an array to STD: vector? (Using vector. insert) (C/C ++) (STL)