C ++ container vector tutorial

Source: Internet
Author: User

Vector is a type of template .. </P> <p> usage: <br/> vector <data type> variable name; </P> <p> vector <int> VI; <br/> there are multiple methods </P> <p> vector <int> VI; save an object of the int type. the initialization value is null <br/> vector <int> VI (V2); V2 is a copy of VI <br/> vector <int> VI (10 ); object saved as Int. the initialization value is 10 <br/> vector <int> VI (n, 10 ); save n elements with a value of 10 </P> <p> press the elements with push_back like a vector. <br/> for example, Vi. push_back (10); <br/> Use VI. empty () determines whether VI is null <br/> Use VI. size () gets the number of VI elements </P> <p> iterator </P> <p> uses iterator to access elements of a vector object .. </P> <p> Method of Using iterator <br/> vector <int>: iterator it </P> <p> iterator begin () and end () method <br/> vector <int>: iterator it = VI. begin (); create the iterator it and initialize the subscript VI [0]; <br/> vector <int >:: iterator it = VI. end (); Create and point the iterator to the end of VI </P> <p> * It indicates the value of the current element (* is the dereference operator) </P> <p> Use Vector <int>: iterator to create an iterator .. access and modify data, vector also provides a const_iterator type <br/> This type only allows access to vector data and cannot be modified </P> <p> the iterator can be calculated as shown in <br /> vector <int>:: iterator it = VI. begin (); It = 0 </P> <p> it + 3; it = 3; </P> <p> it ++; it = 4; and so on </P> <p>

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.