Vector container for C + +

Source: Internet
Author: User

C + + also has a very common container is the vector container, he is an array implementation, is a variable-length container, in many cases can simplify our programming.


Use vector to add header file
#include <vector>
Then using std::vector
or using namespace Std;


Initialization and definition of vectors


Since vector is a function template, so the system does not know what type of vector each element is, so we need to develop, define an int type vector container when,vector<int> A; you can define a vector container in which an element is an int.
There are several ways to initialize it:
Vector<int> A (b)//use another vector to initialize a vector.
Vector<int> A (3,1)//initialization vector is 3 x 1
vector<int> a{1,2,3};//initialization vector is


Adding elements to the vector container


To use the Push_back method built into the class, you can add an element to the last side of the class as if it were a stack.


The other operations are similar to the string container, +,+=, and comparing symbols.

Reprint Link: http://blog.csdn.net/sanwenyublog/article/details/18006769

Vector container for C + +

Related Article

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.