0

I have taken out all the integers from the filenames and sorted the integers following an ascending order. However, I want to print the filenames following the ascending order of sorted integers, and the file names may be differ such that some consists of "image 1.png" and some consists of "ImAGE1.png", and what is important is the integer only, which need to be sorted accordingly. How can I take out all the filenames and print them out following the sequence of sorted integers? (previously the filenames are all not sorted)

Now I have 1,2,3,4... but I need to print something like image1.png, Image2.png and so on which follows the filenames instead of just all sorted integers.. thanks.

void QtWidget::displayImages(string str) {
    ui.images->clear();
    QListWidgetItem *item = new QListWidgetItem();
    QDirIterator it(QStringLiteral("C:\\Users\\Visual Studio 2015\\Projects\\QtWidget\\pic"),
        QStringList() << "*.jpg", QDir::Files, QDirIterator::Subdirectories);
    QFileInfo files;
    faList.clear();

    while (it.hasNext()) {
        QFileInfo file(it.next());
        faList.append(file.fileName());
        _fileNames.append(file.fileName());

    }
        string a = " " + result.toStdString() + " " ;
        str = a;
        stringstream ss;
        
        /* Storing the whole string into string stream */
        ss << str;

        /* Running loop till the end of the stream */
        string temp;
        int found;
        while (!ss.eof()) {

            /* extracting word by word from stream */
            ss >> temp;

            /* Checking the given word is integer or not */
            if (stringstream(temp) >> found)
                _integer.push_back(found);
            

    

            /* To save from space at the end of string */
            temp = "";

        }
                for (int i = 0; i < _integer.size(); i++) {
            int integers = _integer[i];
            sort(_integer.begin(), _integer.end());
        }
        for (auto integer : _integer) {
            cout << "SORTED int:" << integer;
                }
}
Examples of output (filenames) using QDirIterator (Before sorted):
Image1_pic.png
Image10_pic.png
Images11_pics.png
...
Images300.png

(Note that they have different names but unique integers)
Examples of output (integers) (After sorted):
1
2
3
4
Cassey
  • 17
  • 7
  • `std::string filename = "Image" + std::to_string(integervalue) + "_pic.png";`? – Some programmer dude Feb 28 '23 at 07:09
  • On a totally different and unrelated note, please read [Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons) – Some programmer dude Feb 28 '23 at 07:11

0 Answers0