The C + + programming language has an application called vector, and its role is very important in practical programming. Here we will give you a detailed introduction of C + + vector related to the application skills and basic content, I hope to bring some help.
(1) vector< type > identifier;
(2) vector< type > identifier (maximum capacity);
(3) vector< type > identifier (maximum capacity, initial all values);
(4) int i[4] = {12,3,4,5};
vector< type > VI (i, i+2); The value of I index is 3;
(5) vector< vector<int> >//vi defines a 2-dimensional container; Remember to have a space, or it will be an error
vector< int >
Line//When using, you must first initialize the vi row;
for (int i = 0; i < i + +)
{
vector.push_back (line);
}
The individual believes that it is good to define a two-dimensional array using vectors because the length can not be predetermined. Very good.
(6) C + + vector sort
vector< int > VI;
Vi.push_back (1);
Vi.push_back (3);
Vi.push_back (0);
Sort (Vi.begin (), Vi.end ()); /Small to large
reverse (vi.begin (), Vi.end ())///from the Boulevard small
(7) Sequential access
Vector < int > vi;
for (int i = 0; i < i + +)
{
vector.push_back (i);
}
for (int i = 0; i < i + +)///The first invocation method
{
cout <<vector[i] << "";
}
for (Vector<int>::iterator it = Vi.begin ();
it!=vi.end (); it++)///The second invocation method
{
cout << *it << "";
}
(8) Find
Vector < int > vi;
for (int i = 0; i < i + +)
{
vector.push_back (i);
}
Vector < int >::interator it = find (Vi.begin (), vi.end,3);
cout << *it << Endl; Returns the location of the value found within the container.
(9) using arrays to initialize C + + vector
int i[10] ={1,2,3,4,5,6,7,78,8};
The first type of
vector<int> VI (I+1,I+3);///from the 2nd element to the third element for
(vector <int>::interator it = vi.begin ();
It!= vi.end (); it++)
{
cout << *it << "";
}
(10) Type of structural body
struct temp
{public
:
string str;
Public:
int id;
} TMP
int main ()
{
vector <temp> t;
Temp W1;
W1.str = "Hellowor";
W1.id = 1;
T.push_back (t1);
cout << w1.str << "," <<w1.id <<endl;
return 0;
}
The basic introduction of vector C + + is introduced here.