problem using std::copy

Hello,

I have a pointer to an array of doubles that is 2448 in size. I can easily traverse this array and output any or all of the values using pointer arithmetic.

But I wanted to make use of the std::copy(...) to extract columns of values from this array so I can work on them.

1
2
3
4
5
6
7
8
9
10
std::vector < double > db = std::vector < double >(48, 99.9) ;
for (r = 0; r < 51; r++)
{
    std::copy(m_Data + (r + 48), m_Data + 2448, db.begin()) ;
    for (std::vector < double >::const_iterator ci = db.cbegin(); ci != db.cend(); ci++)
    {
        qDebug() << "Value" << *ci ;
    }
}
qDebug() << "Done" ;


Now this code, extracted from the apply() function works as expected but has the undesired side effect of terminating my application! I see the data and the "Done" text appear in the console however I never see my "Success" or "Failure" message appear when I execute:

1
2
3
4
5
6
7
8
if (bp->apply())
{
        qDebug() << "Success" << id ;
}
else
{
	qDebug() << "Failure" ;
}


I can only assume it is something I am doing wrong but to be honest I cannot see what or where it is, so I would really appreciate your comments on this please.

--
Bill
I guess this has nothing to do with the array or std::copy or vector. It's all about qDebug() and bp->apply(). Are you seeing the Success and Failure after you comment out this vector /array/std::copy related code??
I think you have your maths wrong for the pointer arithmetic:
 
std::copy(m_Data + (r * 48), m_Data + (r * 48) + 48, db.begin());

Thank you for the replies. The answer was in fact the math as pointed out by Galik, so thank you very much for that. So back to School for me I guess! Thanks again.

--
Bill
I guess that the wrong math leading to some exception being thrown and the conditional if/else was not being hit.
Also, if you are going to use db.begin() as the OutputIterator (last parameter to std::copy), you need to ensure that the vector is large enough to hold all the elements you're about to copy over because the vector will not be resized.
Topic archived. No new replies allowed.