Solved

# qsort with an vector iterator in .net2003

Posted on 2006-05-10
675 Views
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);
}

0
Question by:cactus1

LVL 86

Expert Comment

Try

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

0

LVL 86

Expert Comment

Or, alternatively

#include <algotrithm>

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

which is the STL way to sort data.
0

Author Comment

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

LVL 86

Accepted Solution

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

Author Comment

Thanks, reference the adress of the array works.
0

## Featured Post

### Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.