Format command line parameter with QString : QString « Qt « C++






Format command line parameter with QString

  

#include <QTextStream>
#include <QCoreApplication>
#include <QStringList>

int main (int argc, char* argv[]) {
    QCoreApplication app(argc, argv);
    QTextStream cout(stdout, QIODevice::WriteOnly);
    QStringList arglst = app.arguments();
    cout << "argc = " << argc << endl;
    for (int i=0; i<arglst.size(); ++i) {
        cout << QString("argv#%1 is %2").arg(i).arg(arglst[i]) << endl;
    }
    int num = arglst[argc - 1].toInt();
    cout << num * 2 << endl;
}

   
    
  








Related examples in the same category

1.Complete demo for QString
2.Using QString as the parameter
3.extends QString
4.cpp with qstring
5.Qt type size