Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand the usage of C++ vector array

Shulou Source: shulou.com Published: 2022-06-03 08:03:37 10月05日 Update

This article mainly explains "how to understand the usage of C++ vector array". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to understand the usage of C++ vector array.

Catalogue

What is the vector array

Second, the basic operation of vector

Initialization of vector array

Insert elements into vector

Delete element

Ergodic array

Using vector to create dynamic two-dimensional array

What is the vector array

Vector is a vector type

A vector array is a dynamic array that can hold any data type.

Similar to ordinary arrays, elements in an array can be referenced by subscript

Second, the basic operation of vector

To use the vector array, add # include to the header file

Declaration of the vector array

Vector vec;// declares the initialization vector vec of an int-type vector vector array (1); / the content in vec is 1p2, 3pyrrine, 4pyrrine, 5vector vec (a); / / declares and initializes the vec vector int a [5] with a vector; vector vec (arecovery5); / / initializes the vector vec with elements of array a (& a [1], & a [4]). / insert an element in the range of a [1]-a [4] into the vector as the initial value of vec / / insert a new element vec.push_back (1) at the end of the vector; / / insert a new element vector::iterator it;it=vec.begin () in front of the iterator; vec.insert (it,5); / / insert a new element in front of the first element / add 3 1 elements to the vector while removing the previous element vec.assign / / now there are only three 1s in the vector to delete the element / / delete the last element vec.pop_back (); / delete the element vec.erase (vec.begin ()) at the specified location; / / delete the element value at the first location / / clear all elements vec,clear (); / / determine whether the array is empty vec.empty (); traverse the array / / use the subscript to access the vector aposition for (int item0bot I) like the array

Tags: Array element vector Clippers content dynamic subscript position basic operation type Chinese plus two-dimensional learning iterative practical ordinary deeper interest only can be passed through Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology NVidia Shulou Tech Info Xiaomi