In C ++ programming language, there is an application method called Vector. Its role is very important in actual programming. Here we will give you a detailed introduction to the application skills and basic content of C ++ Vector, hoping to help you.
- Overview of C ++ header file content
- C ++ pointer drift Solution
- How to use C ++ Builder to Operate Excel tables
- Tips for deleting C ++ container values
- Overview of basic concepts of C ++ set Initialization
(1) vector <type> identifier;
(2) vector <type> identifier (maximum capacity );
(3) vector <type> maximum identifier capacity, all initial values );
(4) int I [4] = {12, 3, 4, 5 };
- Vector <type> vi (I, I + 2); // obtain the value after I index value is 3;
(5) vector <int> // vi defines a 2-dimensional container. Remember to have spaces. Otherwise, an error will be reported.
- Vector <int> line
- // When using the tool, you must first initialize the vi rows;
- For (int I = 0; I <10; I ++)
- {
- Vector. push_back (line );
- }
- /// I personally think it is good to define a two-dimensional array using vector,
Because the length is not predetermined. Good.
(6) C ++ Vector sorting
- 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 () // small from Avenue
(7) sequential access
- Vector <int> vi;
- For (int I = 0; I <10; I ++)
- {
- Vector. push_back (I );
- }
- For (int I = 0; I <10; I ++) // The first call method.
- {
- Cout <vector [I] <"";
- }
- For (vector <int >:: iterator it = vi. begin ();
- It! = Vi. end (); it ++) // The second call Method
- {
- Cout <* it <"";
- }
(8) Search
- Vector <int> vi;
- For (int I = 0; I <10; I ++)
- {
- Vector. push_back (I );
- }
- Vector <int>: interator it = find (vi. begin (), vi. end, 3 );
- Cout <* it <endl; // return the location of the value in the container.
(9) Use arrays to initialize the C ++ Vector.
- Int I [10] = {1, 2, 4, 5, 6, 7, 78, 8 };
- /// First
- Vector <int> vi (I + 1, I + 3); // from the first element to the third element
- For (vector <int >:: interator it = vi. begin ();
- It! = Vi. end (); it ++)
- {
- Cout <* it <"";
- }
(10) struct type
- 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 C ++ Vector is here.