@Blackzero said in "debug assertion failed" error message:
After I looked at my code, I found this, what I want to do is to change the previous byte to a new byte, do I have to change it and how to change it to make it suitable for msvc 2019.
uint8_t array8[] = {114,5,0,240,153,0};
std::copy(std::begin({114, 5, 0, 240, 153}), std::end({114, 5, 0, 240, 153}), std::begin(array8));
What warnings did your compiler issue when it compiled this? I am surprised that mine did not.
The first line fills a C-style array with 6 elements as expected.
The std::copy() line uses:
a temporary five-element list to get a begin() iterator
a
different temporary five-element list to get an end() iterator
tries to put that in the 6-element array8
The two input iterators are unrelated and could be massively far apart in memory. That it did not crash the program (regardless of compiler) is luck.
I think that, "change the previous byte to a new byte," means you wanted to fill array8 with different bytes and resize it to five elements. You cannot resize a C-style array: you need to track the amount of useful data in the 6-byte buffer by some other means. C-strings use a '\0' byte to flag the end of the string but you do not have the luxury of a flag value in your data. You are also responsible for ensuring you never try to put more than 6-elements in the array.
Since this is C++ you should be using std::vector and not C-style arrays. You need to adjust all other code using it.
std::vector<uint8_t>array {114,5,0,240,153,0};
qDebug() << array; // std::vector(114, 5, 0, 240, 153, 0)
array.pop_back();
qDebug() << array; // std::vector(114, 5, 0, 240, 153)
array = std::vector<uint8_t> {1,2,3,4,5,6,7,8};
qDebug() << array; // std::vector(1, 2, 3, 4, 5, 6, 7, 8)
array = std::vector<uint8_t> {10,9,8};
qDebug() << array; // std::vector(10, 9, 8)