jabber status icon danadam@jabster.pl

std and qt iterators

std:

typedef std::map<int, std::string> StdMapString;

void f()
{
    StdMapString mapString;
    mapString[1] = "one";
    mapString[2] = "two";
    mapString[3] = "three";

    StdMapString::iterator it = mapString.begin();
    for (; it != mapString.end(); ++it)
        cout << "key = " << it->first
                << ", value = " << it->second
                << ", size = " << it->second.size()
                << endl;
}

qt:

typedef QMap<int, QString> QtMapString;

void f()
{
    QtMapString mapString;
    mapString[1] = "one";
    mapString[2] = "two";
    mapString[3] = "three";

    QtMapString::iterator it = mapString.begin();
    for (; it != mapString.end(); ++it)
        qDebug() << "key = " << it.key()
                << ", value = " << it.value()
                << ", or value = " << *it
                << ", size = " << it.value().size();
}

See also Understand the Qt containers

Dodaj komentarz

Wcześniejsze wpisy