Skip to content

Instantly share code, notes, and snippets.

@JohannMG
Created September 24, 2020 03:40
Show Gist options
  • Save JohannMG/44da0505cde966051253afa3e5536aed to your computer and use it in GitHub Desktop.
Save JohannMG/44da0505cde966051253afa3e5536aed to your computer and use it in GitHub Desktop.
Confirm: You can iterate through array of char pointers.
#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