I have a function like the following that takes in a pointer to the start of a c style array, creates a vector and then copies the data from this vector into the c style array.
Using std::copy with .begin() and .end() does not copy it properly but the other 2 methods I have posted below work and I was wondering why.
This does not work:
void copyArr(uint8_t* Arr1)
{
std::vector<uint8_t> Arr2;
Arr2.reserve(100);
for ( int i = 0; i < 100; ++i )
{
Arr2[i] = 5;
}
std::copy(Arr2.begin(), Arr2.end(), Arr1);
}
But this will work
void copyArr(uint8_t* Arr1)
{
std::vector<uint8_t> Arr2;
Arr2.reserve(100);
for ( int i = 0; i < 100; ++i )
{
Arr2[i] = 5;
}
// This works.
std::copy(Arr2.begin(), Arr2.begin() + 100, Arr1);
// This will also work.
//std::copy(&Arr2[0], &Arr2[100], Arr1);
}