日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

stl标准模板库_C ++标准模板库(STL)中的数组及其常用功能

發布時間:2025/3/11 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 stl标准模板库_C ++标准模板库(STL)中的数组及其常用功能 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

stl標準模板庫

"array" is a container in C++ STL, which has fixed size, which is defined in "array" header.

“ array”是C ++ STL中的一個容器,具有固定大小,在“ array”標頭中定義。

Declaration:

宣言:

array <data_type, size> array_name = {initializer_list};Example:array<int,5> values {10, 20, 30, 40, 50};

Array class's common functions:

數組類的常用功能:

  • array::operator[] - Gets and sets a reference to an element based on given index.

    array :: operator [] -根據給定的索引獲取并設置對元素的引用。

  • array.empty() - Returns true if array is empty

    array.empty() -如果數組為空,則返回true

  • array.size() - Returns the total number of elements in the array

    array.size() -返回數組中元素的總數

  • array.front() - Return the first element

    array.front() -返回第一個元素

  • array.back() - Returns the last element

    array.back() -返回最后一個元素

  • array.at(index) - Returns the element from given index

    array.at(index) -返回給定索引中的元素

  • array.begin() - Returns the reference pointing to the first element

    array.begin() -返回指向第一個元素的引用

  • array.end() - Returns the reference punting to the last element

    array.end() -返回指向最后一個元素的引用

  • Example:

    例:

    #include <iostream> #include <array>using namespace std;int main() {//array declaring and initializationarray<int, 5> arr = {10, 20, 30, 40, 50};//checking array is empty or not by using empty()if(arr.empty())cout<<"Array is empty!!!"<<endl;elsecout<<"Array is not empty!!!"<<endl;//Array functionscout<<"size: " << arr.size() <<endl;cout<<"first element: " << arr.front() <<endl;cout<<"last element: " << arr.back() <<endl;cout<<"0th element: " << arr.at(0) <<endl;cout<<"3rd element: " << arr.at(3) <<endl;//printing all array elements are: ";for(auto i = arr.begin () ; i != arr.end(); i++)cout<<*i<<" ";cout<<endl;return 0; }

    Output

    輸出量

    Array is not empty!!!size: 5first element: 10last element: 500th element: 103rd element: 4010 20 30 40 50

    Reference: C++ std::array

    參考: C ++ std :: array

    翻譯自: https://www.includehelp.com/stl/array-in-cpp-standard-template-library-with-its-common-functions.aspx

    stl標準模板庫

    總結

    以上是生活随笔為你收集整理的stl标准模板库_C ++标准模板库(STL)中的数组及其常用功能的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。