I used array to store the data, but I replaced with vector, so I would like to replace all the c operators with c++ operators. I used memcpy to copy one memory blocks
for (i = 0; i < rows_; i++)
memcpy((T *) &tmp.data_[cols_ * i], (T *) &a.data_[cols_ * (2 * i + 1)], rows_ * sizeof(T));
It’s also working with vectors, I just want to know is there an equivalent function in c++?
I tried the copy:
std::copy(tmp.data_[cols_ * i], tmp.data_[cols_ * i+rows], a.data_[cols_ * (2 * i + 1)]);
but I’m receiving the following error:
error: invalid use of member function (did you forget the ‘()’ ?)
For example:
I have an 2xnxn size array and I’m using the for cycle to make an nxn array instead. for example I have 1 2 3 4 5 6 7 8, my new array has to be the following: 3 4 7 8. I used memcpy to achieve this, but I don’t know how can I achieve in c++
Use
std::copyorstd::vector::assignif you copy fromarraytovectorif copy from vector to vector
if you don’t need to keep v1,
std::swapalso worksUpdate: