vector::front
提供:cppreference.com
reference front(); const_reference front() const;
コンテナの先頭の要素への参照を返します。
目次 |
[編集] 引数
(なし)
[編集] 戻り値
先頭の要素への参照
[編集] 例
次のコードはユーザーによって入力された文字列群の(アルファベット順での)最初の文字列を 表示するのにvectorとsort()アルゴリズムを使用しています。
vector<string> words; string str; while( cin >> str ) words.push_back(str); sort( words.begin(), words.end() ); cout << "In alphabetical order, the first word is '" << words.front() << "'." << endl;
次の入力が与えられた場合には:
now is the time for all good men to come to the aid of their country
...上記のコードは以下の表示をします:
In alphabetical order, the first word is 'aid'.
[編集] Complexity
constant