📜  C++ STL中的多图撕裂

📅  最后修改于: 2021-05-30 01:56:46             🧑  作者: Mango

multimap :: rend()是C++ STL中的内置函数,它返回一个反向迭代器,该迭代器指向在multimap容器的第一个元素之前的理论元素。

句法

multimap_name.rend()

参数:该函数不带任何参数。

返回值该函数返回一个指向多图容器的另一端的反向迭代器,即指向多图的第一个元素之前的位置的反向迭代器。

multimap :: rend()返回的迭代器无法取消引用。

以下2个程序说明了该函数

// CPP program to illustrate
// multimap::rend()
#include 
#include 
using namespace std;
  
int main()
{
    multimap sample;
  
    // Insert pairs in the multimap
    sample.insert(make_pair('a', 10));
    sample.insert(make_pair('b', 20));
    sample.insert(make_pair('c', 30));
    sample.insert(make_pair('c', 40));
  
    // Show content
    for (auto it = sample.rbegin(); it != sample.rend(); it++)
        cout << it->first << " = " << it->second << endl;
}

输出

c = 40
c = 30
b = 20
a = 10

程序2

// CPP program to illustrate
// multimap::rend()
  
#include 
#include 
using namespace std;
  
int main()
{
    multimap sample;
  
    // Insert pairs in the multimap
    sample.insert(make_pair('a', 10));
    sample.insert(make_pair('b', 20));
    sample.insert(make_pair('c', 30));
    sample.insert(make_pair('c', 40));
  
    // Get the iterator pointing to
    // the preceding position of 1st element of the multimap
    auto it = sample.rend();
  
    // Get the iterator pointing to
    // the 1st element of the multimap
    it--;
    cout << it->first << " = " << it->second;
}

输出

a = 10
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”