I can't use file size as array size, because it should be a constant. But I made it constant.
ifstream getsize(dump, ios::ate);
const int fsize = getsize.tellg(); // gets file size in constant variable
getsize.close();
byte dumpArr[fsize] // not correct
array<byte, fsize> dumpArr // also not correct
byte *dumpArr = new byte[fsize]; // correct, but I can't use dynamic array
I need to create std::array with the file size.
You need a compile-time constant to declare arrays so you have two options:
std::vector
instead:
std::ifstream file("the_file");
std::vector<std::uint8_t> content(std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>{});
program: source.cpp filesize.h
g++ -o program source.cpp
filesize.h: the_file
stat --printf '#pragma once\n#define FILESIZE %sULL\n' the_file > header.h
... and use FILESIZE
inside source.cpp
to declare your array.