命名空间
变体
操作

std::multiset<Key,Compare,Allocator>::begin, std::multiset<Key,Compare,Allocator>::cbegin

来自 cppreference.cn
< cpp‎ | 容器‎ | multiset
 
 
 
 
iterator begin();
(1) (noexcept since C++11)
const_iterator begin() const;
(2) (noexcept since C++11)
const_iterator cbegin() const noexcept;
(3) (since C++11)

返回指向 multiset 首个元素的迭代器。

如果 multiset 为空,则返回的迭代器将等于 end()

range-begin-end.svg

内容

[编辑] 返回值

指向首个元素的迭代器。

[编辑] 复杂度

常数时间复杂度。

注意

由于 iteratorconst_iterator 都是常量迭代器(并且实际上可能是同一类型),因此无法通过这些成员函数返回的迭代器来修改容器的元素。

libc++ 向后移植了 cbegin() 到 C++98 模式。

[编辑] 示例

#include <iostream>
#include <iterator>
#include <set>
#include <string>
 
int main()
{
    const std::multiset<std::string> words =
    {
        "some", "not", "sorted", "words",
        "will", "come", "out", "sorted",
    };
 
    for (auto it = words.begin(); it != words.end(); )
    {
        auto count = words.count(*it);
        std::cout << *it << ":\t" << count << '\n';
        std::advance(it, count); // all count elements have equivalent keys
    }
}

输出

come:	1
not:	1
out:	1
some:	1
sorted:	2
will:	1
words:	1

[编辑] 参见

(C++11)
返回指向末尾的迭代器
(public member function) [编辑]
(C++11)(C++14)
返回指向容器或数组开头的迭代器
(function template) [编辑]