QHashの全ての要素を削除
解説
clear()はQHashの全ての要素を削除します.
定義は以下の通りです.
void QHash::clear ()
削除後,QHashの要素数は0になります.
使用例
#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.size() << "\n"; // 3
hash.clear(); // hash = {}
out << hash.size() << "\n"; // 0
return 0;
}
出力
3
0
最終更新:2011年09月23日 19:22