0

:'(
Hi geeks!, since I started programming I have never used qsort() for sorting. I also tried to consult books but, 'little or no success!'.

Can anyone who know better help me to understand qsort() function.
Please do it with an example!

Happy forever even faced with c++!

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by jencas
0

Wot a quick reply! Thanks jencas I 'l have a look at it. One more question, Can I sort a listbox containing strings?
:icon_cool:

How about loading all the strings to a vector and sorting that vector?
example:

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{

    vector<string> allStrings;
    allStrings.push_back("bbb");
    allStrings.push_back("abb");
    allStrings.push_back("aaa");
    allStrings.push_back("aba");
    allStrings.push_back("aac");

    sort(allStrings.begin(), allStrings.end());

    for (int i = 0; i < allStrings.size(); i++)
        cout << allStrings[i] << "\n";

    cin.get();
    return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.