Vector, which represents the container for the object, and all object types are the same.
Definition and initialization:
Vector<int> A; Default initialization, empty vector, no element
Vector<int> B (a); Equivalent to a copy of all elements in a in b=a;b
Vector<int> C (N, Val); Contains n repeating elements with a value of Val
Vector<int> c (n); Contains n elements, value is initialized by default
Vector<int> d{a,b,c,d..} The element that contains the number of initial values, each of which is given a corresponding value, equivalent to D={a,b,c,d ...}
Vector<string> v7{10}//There are 10 default initialized elements
If parentheses are used, the provided value is used to construct the vector object;
If you use curly braces, you want the list to be initialized
Add an element to a vector object: Take advantage of its member function push_back ()
1:
Vector<int> v;
for (int i=0; i!=100; ++i)
V.push_back (i);
2:
Vector<int> v;
int A;
while (Cin>>a)
V.push_back (a);
Access:
1: Range for statement
Vector<int> v{1,2,3,4,5};
for (auto &i:v)
I+=i;
2: Subscript operator
Vector<unsigned> scores (11,0);
unsigned grade;
while (Cin>>grade)
if (grade<=100)
++SCORES[GRADE/10];
Note: You cannot add an element with the subscript operator.
Standard library type vector[c++ Primer]