14 QMap<QString,
int> map;
27 map.insert(
"twelve", 12);
33 int num1 = map[
"thirteen"];
34 int num2 = map.value(
"thirteen");
41 if (map.contains(
"TIMEOUT"))
42 timeout = map.value(
"TIMEOUT");
48 int timeout = map.value(
"TIMEOUT", 30);
54 QMapIterator<QString,
int> i(map);
57 cout << qPrintable(i.key()) <<
": " << i.value() << endl;
64 for (
auto i = map.cbegin(), end = map.cend(); i != end; ++i)
65 cout << qPrintable(i.key()) <<
": " << i.value() << endl;
71 map.insert(
"plenty", 100);
72 map.insert(
"plenty", 2000);
79 QMap<QString,
int> map;
81 for (
int value : std::as_const(map))
82 cout << value << endl;
137 QMap<
int, QString> map;
138 map.insert(1,
"one");
139 map.insert(5,
"five");
140 map.insert(10,
"ten");
152 QMap<QString,
int> map;
153 map.insert(
"January", 1);
154 map.insert(
"February", 2);
156 map.insert(
"December", 12);
158 for (
auto i = map.cbegin(), end = map.cend(); i != end; ++i)
159 cout << qPrintable(i.key()) <<
": " << i.value() << endl;
164 QMap<QString,
int> map;
167 for (
auto i = map.begin(), end = map.end(); i != end; ++i)
173 QMap<QString,
int> map;
176 QMap<QString,
int>::const_iterator i = map.cbegin();
177 while (i != map.cend()) {
187 QMap<QString,
int> map;
190 erase_if(map, [](
const QMap<QString,
int>::iterator it) {
return it.value() > 10; });
195 QMap<QString, QString> map;
196 auto i = map.begin();
199 if (i.key() ==
"Hello")
200 i.value() =
"Bonjour";
206 QMap<QString,
int> map;
207 map.insert(
"January", 1);
208 map.insert(
"February", 2);
210 map.insert(
"December", 12);
212 for (
auto i = map.cbegin(), end = map.cend(); i != end; ++i)
213 cout << qPrintable(i.key()) <<
": " << i.value() << endl;
218 QMap<
int, QString> map;
221 for (QMap<
int, QString>::const_iterator it = map.cbegin(), end = map.cend(); it != end; ++it) {
222 cout <<
"The key: " << it.key() << endl;
223 cout <<
"The value: " << qPrintable(it.value()) << endl;
224 cout <<
"Also the value: " << qPrintable(*it) << endl;
231 QMap<QObject *,
int> map2;
232 auto isPrimeNumber = [](
int num) {
return true; };
236 QList<
int> keys = map.keys();
237 int numPrimes = std::count_if(map.cbegin(), map.cend(), isPrimeNumber);
238 qDeleteAll(map2.keys());
241 int primeNums = std::count_if(map.keyBegin(), map.keyEnd(), isPrimeNumber);
242 qDeleteAll(map2.keyBegin(), map2.keyEnd());
248 QMap<QString,
int> map;
249 map.insert(
"January", 1);
250 map.insert(
"February", 2);
252 map.insert(
"December", 12);
254 for (
auto [key, value] : map.asKeyValueRange()) {
255 cout << qPrintable(key) <<
": " << value << endl;