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 function of C++ 's array?

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

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

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

Internet Technology

Wechat

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

12
Report