Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between push method and push_back method in C++

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report