vector initialization method

(1) the constructor with no arguments initialization

// initialization of a size for the vector 0

vector<int> abc;

Constructor initializes (2) with parameters

// Initialization size, but each element is the default value

vector <int> abc (10); // initialize the default value of 10 elements of 0

// Initialization size, and set the initial value

vector <int> cde (10, 1); // initializes the 10 elements of the value 1

(3) initializing the array address

int a[5] = {1,2,3,4,5};

// initialize the address array a, note is the address (the left and right closed opening) from 0 to 5

(4) the initialization vector by the same type

vector<int> a(5, 1);

// initialized by a

vector<int> b(a);

 

Guess you like

Origin www.cnblogs.com/jianfeifeng/p/11014686.html