[Solved] Access violation writing location 0x00000000 when reading/writing to vector


You need to allocate the vector elements before assigning values to them, when you do

vector<int> arr; // defines an empty vector.
arr[y] = ...     // access element at position y.

arr here is empty, pointing to a zero array, you are trying to write at memory 0x0000.

Checkout vector documentation, to see the different ways to initialize it.

In C++ you need to handle your memory, you cannot just port code from different higher-level languages.


There are different ways to do it, for instance

vector<int> arr;
arr.reserve(amount);
for (int y = 0; y < amount; ++y) {
  arr.push_back(values[offset + y]);
}

6

solved Access violation writing location 0x00000000 when reading/writing to vector