挿入
解説
prepend(),push_front()は引数で指定した値をQListの先頭に追加します.prepend()とpush_front()の処理内容は同じです.
append(),<<,push_back() は引数で指定した値をQListの末尾に追加します.append()とpush_back()と<<の処理内容は同じです.
定義は以下の通りです.
void QList::append ( const T & value )
void QList::prepend ( const T & value )
QList<T> & QList::operator<< ( const T & value )
void QList::push_front ( const T & value )
void QList::push_back ( const T & value )
引数valueには挿入する値を指定します.
push_front(),push_back()はSTLに対する上位互換のために用意されています.
使用例
#include <QTextCodec>
#include <QTextStream>
#include <QList>
int main(int argc, char *argv[]) {
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
QTextStream out(stdout);
QList<QString> lst;
lst.prepend("0"); // vec = ("0")
lst.prepend("1"); // vec = ("1", "0")
lst.append("a"); // vec = ("1", "0", "a")
lst.append("b"); // vec = ("1", "0", "a", "b")
lst << "!"; // vec = ("1", "0", "1", "b", "!")
lst << "@"; // vec = ("1", "0", "1", "b", "!", "@")
foreach(QString str, lst) {
out << str << ",";
}
out << "\n";
return 0;
}
出力
1,0,a,b,!,@,
最終更新:2011年09月18日 19:38