数组::C++ STL中的CREXEN(和):数组::

  1. 数组::crbegin() 是C++ STL中的一个内置函数,它返回指向容器中最后一个元素的常数反向迭代器。

    语法:

    array_name.crbegin()

    参数: 该函数不接受任何参数。

    返回值: 该函数返回指向容器中最后一个元素的反向迭代器。

    用于演示array::crbegin()方法的程序:

    项目1:

    // CPP program to illustrate
    // the array::crbegin() function
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    // array initialisation
    array< int , 5> arr = { 1, 5, 2, 4, 7 };
    // prints the last element
    cout << "The last element is " << *(arr.crbegin()) << endl;
    // prints all the elements
    cout << "The array elements in reverse order are:" ;
    for ( auto it = arr.crbegin(); it != arr.crend(); it++)
    cout << *it << " " ;
    return 0;
    }

    
    

    输出:

    The last element is 7
    The array elements in reverse order are:
    7 4 2 5 1
    

  2. 数组::crend() 是C++ STL中的一个内置函数,它返回一个常数反向迭代器,指向数组容器中第一个元素之前的理论元素。

    语法:

    array_name.crend()

    参数: 该函数不接受任何参数。

    返回值: 该函数返回一个常量反向迭代器,指向数组容器中第一个元素之前的理论元素。

    用于演示array::crend()方法的程序:

    项目1:

    // CPP program to illustrate
    // the array::crend() function
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    array< int , 5> arr = { 1, 5, 2, 4, 7 };
    // prints all the elements
    cout << "The array elements in reverse order are:" ;
    for ( auto it = arr.crbegin(); it != arr.crend(); it++)
    cout << *it << " " ;
    return 0;
    }

    
    

    输出:

    The array elements in reverse order are:
    7 4 2 5 1
    

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享