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