指定した要素を含むか確認
解説
contains()はQListに特定の値が含まれているかどうかを取得します.含まれている場合にはtrue,そうでない場合にはfalseが返します.
定義は以下の通りです.
bool QList::contains ( const T & value ) const
引数valueには確認対象の値を指定します.
使用例
#include <QTextCodec>
#include <QTextStream>
#include <QList>
int main(int argc, char *argv[]) {
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
QTextStream out(stdout);
QList<QString> lst;
lst << "a" << "b" << "c" << "d" << "e"; // lst = ("a", "b", "c", "d", "e")
out << lst.contains("a") << "\n";
out << lst.contains("A") << "\n";
return 0;
}
出力
1
0
最終更新:2011年09月18日 19:49