What is the difference between push method and push_back method in C++
The purpose of this article is to share with you the difference between push method and push_back method in C++. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
[text]
Introduction of push_back method
Vector::void push_back (const value_type& val)
Vector::void push_back (value_type&& val)
This function adds a new element to the end of the vector, the position is the next element of the current last element, and the value of the new element is a copy (or mobile copy) of the val.
Introduction to common methods of vector
(1) vector
< 类型 >Identifier
(2) vector
< 类型 >Identifier (maximum capacity); (3) vector
< 类型 >Identifiers (maximum capacity, initial all values); (4) int I [4] = {12pr 3pm 4Gen 5}; vector
< 类型 >Vi (I, iTun2); / / get the value after the I index is 3; (5) vector
< vector >/ / vi defines a two-dimensional container; remember that there must be spaces, otherwise an error may be reported
Vector
< int >When using line / /, be sure to initialize vi lines first; for (int I = 0; I)
< 10 ; i ++) { vector.push_back(line); } vector 定义二维数组,长度可以不预先确定。(6)C++ vector排序 vector< int >Vi; vi.push_back (1); vi.push_back (3); vi.push_back (0); sort (vi.begin (), vi.end ()); / / from small to large reverse (vi.begin (), vi.end ()); / / from big to small
(7) sequential access
Vector
< int >Vi; for (int I = 0; I < 10; I + +) {vi.push_back (I);} for (int I = 0; I < 10; I + +) / / the first calling method {cout