I was wondering and have not found any advice, on how to convert a C-style integer array to a new std::array from C++11
I love the std::array and use it a lot, anyhow if I read in data from binary files, I work around to copy the values. Isn't there a simpler way when using fread?
FILE* fp; // initalize not important here
int arr[12];
std::array<int,12> stdarr;
fread(arr, sizeof(int), 12, fp);
for(int i=0; i < 12; i++)
stdarr[i] = arr[i];
Reading into the address of the first element array's underlying data block should work:
fread(stdarr.data(), sizeof(int), stdarr.size(), fp);
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