名前空間
変種

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

提供: cppreference.com
 
 
 
 
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
iterator begin();
(C++11未満)
iterator begin() noexcept;
(C++11以上)
const_iterator begin() const;
(C++11未満)
const_iterator begin() const noexcept;
(C++11以上)
const_iterator cbegin() const noexcept;
(C++11以上)

コンテナの最初の要素を指すイテレータを返します。

コンテナが空の場合は、返されたイテレータは end() と等しくなります。

引数

(なし)

戻り値

最初の要素を指すイテレータ。

計算量

一定。

ノート

iteratorconst_iterator はどちらも定数イテレータである (実際には同じ型かもしれない) ため、これらのメンバ関数のいずれによって返されたイテレータを通してもコンテナの要素を変更することはできません。

#include <set>
#include <iostream>
 
int main() {
  std::set<int> set = { 6, 1, 3, 4, 2, 5 };
  for (auto it = set.begin(); it != set.end(); ++it)
    std::cout << *it << "\n";
}

出力例:

1
2
3
4
5
6

関連項目

終端を指すイテレータを返します
(パブリックメンバ関数) [edit]