(Original partition) how to convert an array to STD: vector? (Using constructor) (C/C ++) (STL)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.