• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 693
  • Last Modified:

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.
0
cactus1
Asked:
cactus1
  • 3
  • 2
1 Solution
 
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
 
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
 
cactus1Author Commented:
Thanks, reference the adress of the array works.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now