Vector provides an alternative to built-in arrays, called vectors, and is a type of STL container.
* Reference header files
# I nclude
# I nclude
# If _ msc_ver> 1020
Using namespace STD;
# Endif
* Definition
Vector Ivec (10); // The initialization size is 10 elements.
Vector Ivec (10, 8); // use 8 to initialize each element.
Char A [10] = {1, 2, 8, 7, 20, 88, 22, 35, 72 };
Vector Ivec (A, A + 4); // initialize with an existing array and give the start address and end address respectively.
Vector Ivec (& A [3], & A [6]);
Vector cannot use the definition method below the Array
Vector Ivec = {2, 8, 3}; // Error
Vector Ivec2 = ivec; // you can directly assign values using another vector of the same type.
* Size () query size. Check whether empty () is empty.
If (ivec. Empty ())
Return;
* Push_back (): inserts an element.
Ivec. push_back (8 );
The size of the extended vector does not overwrite the original element.
* Access by ARRAY
Vector Ivec (10 );
For (INT I = 0; I : Iterator it = ivec. Begin (); it! = Ivec. End (); ++ it)
{
Printf ("% d/N", * it );
}
Bool is_equal (const int * IA, int ia_size,
Const Vector & Ivec)
{
If (ia_size = ivec. Size () return true;
Int I = 0;
For (vector : Const_iterator it = ivec. Begin (); it! = Ivec. End (); It ++)
{
If (* It! = Ia [I ++])
Return false;
If (I = ia_size)
Break;
}
Return true;
}
When declared as const Vector & Ivec, use the constant iteration object Vector : Const_iterator it