I have fixed length char array used to store my decoded data. Once finish decoding, I want to copy content of the char array to a char vector for later use. When debugging to the line of “std:copy(…)” an error occurred. What’s wrong with my std::copy usage?
Thank you!
std::vector<char> m_cCalibrationID;
char cCalibrationID[5];
memcpy(cCalibrationID, pszData, 4);
cCalibrationID[4] = 0;
// Copy to vector
std::copy ( cCalibrationID, cCalibrationID + 4, m_cCalibrationID.begin() );
Ignoring that you named them the same thing and pretending you didn’t, you need to allocate space for your vector first:
Or you can use
std::back_inserter:That will
push_backeach copied element. That said, why not skip the middleman?