begin

提供:cppreference.com
移動: 案内, 検索

Syntax:

    #include <vector>
    iterator begin();
    const_iterator begin() const;

begin()関数はベクタの最初の要素へのiteratorを返却する。また、 定数時間で動作する。

例えば、次のコードはbegin()関数を使ってベクタの要素を走査するiteratorを初期化している。

    vector<string> words;
    string str;
 
    while( cin >> str ) words.push_back(str);
 
    for( vector<string>::const_iterator iter = words.begin();
         iter != words.end(); ++iter ) {
      cout << *iter << endl;
    }

次の入力が与えられた時:

    hey mickey you're so fine

上記のコードは次の出力をする:

    hey
    mickey
    you're
    so
    fine

Related Topics: [] operator, at, end, rbegin, rend

個人用ツール
名前空間
変種
操作
案内
ツールボックス
他の言語