QList > removeAt

特定位置の要素を削除

解説

removeAt()はQListの指定した位置の要素を削除します.
removeFirst(),pop_front()はQListの最初の要素削除します.
removeLast(),pop_back()はQListの最後の要素を削除します.

定義は以下の通りです.
void QList::removeAt ( int i )
void QList::removeFirst ()
void QList::removeLast ()
void QList::pop_front ()
void QList::pop_back ()
removeAt()の引数iには削除する位置を指定します.

pop_front(),pop_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"; // vec = ("0", "1", "2", "3")
  10. lst.removeAt(1); // lst = ("0", "2", "3")
  11. lst.pop_front(); // lst = ("2", "3")
  12. lst.pop_back(); // lst = ("2")
  13. foreach(QString str, lst) {
  14. out << str << ",";
  15. }
  16. out << "\n";
  17. return 0;
  18. }

出力
2,
最終更新:2015年06月25日 10:41
ツールボックス

下から選んでください:

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