std::deque<T,Allocator>::front
提供: cppreference.com
reference front(); |
||
const_reference front() const; |
||
コンテナ内の最初の要素を指す参照を返します。
空のコンテナに対する front の呼び出しは未定義です。
引数
(なし)
戻り値
最初の要素を指す参照。
計算量
一定。
ノート
コンテナ c に対して、式 c.front() は *c.begin() と同等です。
例
以下のコードは front を使用して std::deque<char> の最初の要素を表示します。
Run this code
#include <deque>
#include <iostream>
int main()
{
std::deque<char> letters {'o', 'm', 'g', 'w', 't', 'f'};
if (!letters.empty()) {
std::cout << "The first character is: " << letters.front() << '\n';
}
}
出力:
The first character is o
関連項目
| 最後の要素にアクセスします (パブリックメンバ関数) |