C++ Set 库 - begin 函数
描述
它返回一个引用集合容器中第一个元素的迭代器。
声明
以下是 std::set::begin 在各种 C++ 版本中的工作方式。
C++98
iterator begin(); const_iterator begin() const;
C++11
iterator begin() noexcept; const_iterator begin() const noexcept;
返回值
它返回一个引用集合容器中第一个元素的迭代器。
异常
它从不抛出异常。
时间复杂度
Time complexity is contstant.
示例
以下示例显示了 std::set::begin 的用法。
#include <iostream>
#include <set>
int main () {
int myints[] = {50,40,30,20,10};
std::set<int> myset (myints,myints+10);
std::cout << "myset contains:";
for (std::set<int>::iterator it = myset.begin(); it!=myset.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
上述程序将正确编译和执行。
myset contains: 0 1 10 20 30 40 50 26390 2065620553

