What is the function of C++ 's array?
This article mainly explains "what is the role of C++ 's array". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the role of C++ 's array?"
Let's first take a look at how to use array.
To use array, you first need to include the header file in your code:
# include
Because array is a class in the standard library, you need to specify the namespace:
Using std:array
Or specify the namespace directly before array:
Std::array..
Let's take a look at how to define array objects. Go straight to the sample code.
# include
Using std::array
Int main () {
Std::array a1 {{1, 2, 3}}
Std::array a2 = {1,2,3}
Std::array A3 = {std::string ("a"), "b"}
}
From the above example, we can clearly see the difference between the definition of array and vector. When array is defined, you need to specify the size of the container and match the actual number of elements in the container. Others are basically the same as vector. Like vector, array also has some operations for element access, which is basically the same as vector, so put the sample code directly:
/ / array Demo
# include
# include
Using std::array
Int main ()
{
Array arr1 = {1,2,3,4}
Std::cout