byte test[4];
memset(test,0x00,4);
test[]={0xb4,0xaf,0x98,0x1a};
the above code is giving me an error expected primary-expression before ']' token. can anyone tell me whats wrong with this type of assignment?
Arrays cannot be assigned. You can only initialize them with the braces.
The closest you can get, if you want to "assign" it later, is declaring another array and copying that:
const int array_size = 4;
char a[array_size] = {}; //or {0} in C.
char b[array_size] = {0xb4,0xaf,0x98,0x1a};
std::copy(b, b + array_size, a);
or using the array class from std::tr1 or boost:
#include <tr1/array>
#include <iostream>
int main()
{
std::tr1::array<char, 4> a = {};
std::tr1::array<char, 4> b = {0xb4,0xaf,0x98,0x1a};
a = b; //those are assignable
for (unsigned i = 0; i != a.size(); ++i) {
std::cout << a[i] << '\n';
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With