Sorting a vector of strings into numerical order.

I have a vector of strings that contain a list of channels like this:

101,99,22HD,432,300HD

I have tried using the sort routine like this:

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

For some reason my channels are not being sorted at all. I was hoping someone might have some input that might help me come to a resolution to this problem.

Thank you! :slight_smile:

What language is this?

The language is C++ and the solution is this: I copy pasted directly in to my code and it worked great.

struct myLessThan : public binary_function< string, string, bool > { bool operator()( first_argument_type e1, second_argument_type e2 ) const { // TODO 1: // optionally preprocess e1 and e2 here and strip the "HD" postfix // or consider it for the actual comparison later on // TODO 2: // use an alternative string-to-int conversion istringstream is1(e1), is2(e2); int i1, i2; is1 >> i1; is2 >> i2; return i1 < i2; } }; // use the functor like this: sort(mychans.begin(),mychans.end(),myLessThan());