qsort with an vector iterator in .net2003

Hello,

Has anyone been able to use qsort in .net2003, I am using C++.
I have some 6.0 code that I am coverting with the qsort function, it works in 6.0 with a vector iterator but not in .net2003.

static void SortDouble(DoubleVector &d)
{
      DoubleVector::iterator ite = d.begin();

      qsort(ite, d.size(), sizeof(double),DoubleSortFunc);
}

Thanks in advance.
cactus1Asked:
Who is Participating?
 
jkrCommented:
I'd go for 'sort()', 'qsort()' is not STL and more C than C++. But, anyway, give

static void SortDouble(DoubleVector &d)
{
     DoubleVector::iterator ite = d.begin();

     qsort((double*)&d[0], d.size(), sizeof(double),DoubleSortFunc);
}

a try.
0
 
jkrCommented:
Try

     qsort((double*)ite, d.size(), sizeof(double),DoubleSortFunc);

instead. The newer compiler is quite strict.

0
 
jkrCommented:
Or, alternatively

#include <algotrithm>

     std::sort(d.begin(),d.end());

which is the STL way to sort data.
0
 
cactus1Author Commented:
I tried the cast and got the error,

error C2440: 'type cast' : cannot convert from 'std::vector<_Ty,_Ax>::iterator' to 'double *'

I can get the sort to work but what about the qsort, anyone ever used qsort in 2003
0
 
cactus1Author Commented:
Thanks, reference the adress of the array works.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.