Hello! I am using std::istream::read to read the contents of a file, N bytes at a time. I noticed that the last part of the file is not returned.
string fname = "output/input";
ifstream inputfile (fname);
if (!inputfile.is_open()) {
fprintf(stderr, "Failed to open input file, reason: %d\n", errno);
exit(1);
}
vector<char> vec(seg_size - sizeof(int));
while(inputfile.read(vec.data(), vec.size())) {
vec.resize(inputfile.gcount());
process_input_part(vec);
vec.resize(seg_size - sizeof(int));
}
relevant stackoverflow post: https://stackoverflow.com/questions/50491833/how-do-you-read-n-bytes-from-a-file-and-put-them-into-a-vectoruint8-t-using-it
Can you please tell me what I am doing wrong and how I can make sure that the last part of the file is also returned?