QList > first

最初・最後の要素を取得

解説

first(),front()はQListの最初の要素を返します.first()とfront()の処理内容は同じです.
last(),back()はQListの最後の要素を返します.last()とback()の処理内容は同じです.

定義は以下の通りです.
T & QList::first ()
const T & QList::first () const
T & QList::last ()
const T & QList::last () const
T & QList::front ()
const T & QList::front () const
T & QList::back ()
const T & QList::back () const

front(),back()はSTLに対する上位互換のために用意されています.

使用例

  1. #include <QTextCodec>
  2. #include <QTextStream>
  3. #include <QList>
  4. int main(int argc, char *argv[]) {
  5. QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
  6. QTextStream out(stdout);
  7.  
  8. QList<QString> lst;
  9. lst << "0" << "1" << "2" << "3"; // lst = ("0", "1", "2", "3")
  10. out << lst.first() << "\n"; // 0
  11. out << lst.last() << "\n"; // 3
  12. return 0;
  13. }

出力
0
3
最終更新:2011年09月18日 19:22
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。