Created
September 24, 2020 03:40
-
-
Save JohannMG/44da0505cde966051253afa3e5536aed to your computer and use it in GitHub Desktop.
Confirm: You can iterate through array of char pointers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QCoreApplication> | |
#include <QMap> | |
#include <QMapIterator> | |
#include <QDebug> | |
using StringIntMap = QMap<const char*, int>; | |
void addToMap(StringIntMap &map, const char* key, int value) | |
{ | |
map[key] = value; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
StringIntMap goodmap; | |
const char* elsewhere[] = { | |
"some", | |
"good", | |
"fucking", | |
"food" | |
}; | |
for (auto key : elsewhere){ | |
goodmap[key] = 400; | |
} | |
addToMap(goodmap, "function1", 200); | |
addToMap(goodmap, "function2", 400); | |
QMapIterator<const char*, int> iter(goodmap); | |
while (iter.hasNext()) { | |
iter.next(); | |
qDebug() << iter.key() << " = " << iter.value(); | |
} | |
/* prints: | |
some = 400 | |
good = 400 | |
fucking = 400 | |
food = 400 | |
function1 = 200 | |
function2 = 400 | |
*/ | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment