再來一個很蛋的C++程序

#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QtCore>


QStringList names;
QStringList  nodes1;
QStringList  nodes2;
QList<QStringList> nodeslist;
int getName(QString &name, int idx);
int getNode(QString &node, int idx1, int idx2);
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    names << "name0" << "name1";
    nodes1 << "nodes0" << "nodes1" << "nodes2" << "nodes3";
    nodes2 << "nodes0" << "nodes1" << "nodes2" << "nodes3" << "nodes4";
    nodeslist.append(nodes1);
    nodeslist.append(nodes2);


    for(int i=0; i<names.size(); i++){
        if(getName(names.value(i),i) == 0){
            qDebug() << "name" <<names.value(i);
        }
        for(int j=0;j<nodeslist.at(i).size(); j++){
            if(getNode(nodeslist.value(i).value(j),i,j) == 0){
                qDebug() << "node" << nodeslist.value(i).value(j);
            }

        }

    }

    return a.exec();
}


int getName(QString &name,int idx){
    if(idx > names.size()|| idx < 0){
        return -1;
    }
    else{
        name = names.value(idx);
        return 0;
    }
}

int getNode(QString &node,int idx1,int idx2){
    if(idx2 > nodeslist.value(idx1).size() || idx2 < 0){
        return -1;
    }
    else{
        node = nodeslist.value(idx1).value(idx2);
        return 0;
    }
}

發佈了122 篇原創文章 · 獲贊 44 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章