名稱空間
變體
操作

std::unordered_multiset<Key,Hash,KeyEqual,Allocator>::begin, std::unordered_multiset<Key,Hash,KeyEqual,Allocator>::cbegin

來自 cppreference.com
 
 
 
 
iterator begin() noexcept;
(1) (C++11 起)
const_iterator begin() const noexcept;
(2) (C++11 起)
const_iterator cbegin() const noexcept;
(3) (C++11 起)

返回 unordered_multiset 中第一個元素的迭代器。

如果 unordered_multiset 為空,則返回的迭代器將等於 end()

range-begin-end.svg

目錄

[編輯] 返回值

指向第一個元素的迭代器。

[編輯] 複雜度

常數時間。

注意

由於 iteratorconst_iterator 都是常量迭代器(實際上可能是同一型別),因此無法透過這些成員函式返回的迭代器修改容器的元素。

[編輯] 示例

#include <iostream>
#include <iterator>
#include <string>
#include <unordered_set>
 
int main()
{
    const std::unordered_multiset<std::string> words =
    {
        "some", "words", "to", "count",
        "count", "these", "words"
    };
 
    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
    }
}

可能的輸出

some:   1
words:  2
to:     1
count:  2
these:  1

[編輯] 參閱

返回指向末尾的迭代器
(public member function) [編輯]
(C++11 起)(C++14 起)
返回指向容器或陣列開頭的迭代器
(函式模板) [編輯]