std::multiset<Key,Compare,Allocator>:: begin, std::multiset<Key,Compare,Allocator>:: cbegin
From cppreference.net
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::multiset
| Member functions | |||||||||||||||||||||||||||
| Non-member functions | |||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
| Deduction guides (C++17) | |||||||||||||||||||||||||||
|
iterator begin
(
)
;
|
(1) |
(自 C++11 起为 noexcept)
(自 C++26 起为 constexpr) |
|
const_iterator begin
(
)
const
;
|
(2) |
(自 C++11 起为 noexcept)
(自 C++26 起为 constexpr) |
|
const_iterator cbegin
(
)
const
noexcept
;
|
(3) |
(自 C++11 起)
(自 C++26 起为 constexpr) |
返回指向 * this 首元素的迭代器。
如果 * this 为空,返回的迭代器将等于 end() 。
目录 |
返回值
指向第一个元素的迭代器。
复杂度
常量。
注释
由于
iterator
和
const_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); // 所有count个元素都具有等价的键 } }
输出:
come: 1 not: 1 out: 1 some: 1 sorted: 2 will: 1 words: 1
参见
|
(C++11)
|
返回指向末尾的迭代器
(公开成员函数) |
|
(C++11)
(C++14)
|
返回指向容器或数组起始位置的迭代器
(函数模板) |