this is probably a really basic C++ question but I'm very new to C++ so your patience and help is appreciated.
I'm not quite sure why the following code is unable to print out the content of the matrix. I should mention that the variable K
is the integer 3.
std::vector<uint8_t> enc_matrix;
for(size_t i = 0; i != K; ++i) {
enc_matrix[i*(K+1)] = 1;
cout << "enc_matrix: " << enc_matrix[i*(K+1)] << endl;
// cout << enc_matrix.at(i*(K+1)) //doesn't show anything either
cout << "i: " << i*(K+1) << endl;
}
For whatever reason nothing gets printed for enc_matrix[i*(K+1)]
but the result of i*(K+1)
does get printed. Below is what gets printed:
enc_matrx:
i: 0
enc_matrx:
i: 4
enc_matrx:
i: 8
I'm not sure if it has anything to do with the type of the matrix so I've included the additional info below:
typeid(enc_matrix[0]).name()
=> h
and
typeid(enc_matrix).name()
=> St6vectorIhSaIhEE
Why is it that enc_matrix
doesn't get printed? I am expecting to see 1
assigned to it when i
equals to 0, 4 and 8. Thank you.