const
variables can't be modified after declaration. I know I can define a const int
by:
const int a[5]={0,1,2,3,4};
But the problem is that I don't know exactly what the data is. And reading the data only once is enough, and can I store these in a const array by some pointer operations? I will appreciate it if you may give some hints :)
Use a function:
std::vector<int> readArray()
{
std::vector<int> array;
// populate array
return array;
}
Then:
const std::vector<int> constArray = readArray();
Replace std::vector
with std::array
if you know the number of elements beforehand.
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