I am using the following code to read in a file, 1024 bytes at a time. The issue I am having is the last portion of the file is not being read and written to my output file. I am guessing that is because it does not completely fill the 1024 byte size but not sure if this is correct. I am not sure how to change the loop to calculate the last size if that is the problem. Thanks in advanced for any help or suggestions.
ofstream debugFile;
// open file for appending (creates file if it does not exist)
debugFile.open("debug.txt", ios::out | ios::app);
// check if the file to read from exists and if so read the file in chunks
ifstream ifile(logFilePath, std::ifstream::binary);
if (ifile.good())
{
std::vector<char> buffer (1024,0); // read the first 1024 bytes
while (ifile.read(buffer.data(), buffer.size()))
{
debugFile << logFilePath.c_str() << " exists!" << endl;
std::streamsize s=ifile.gcount();
debugFile << "Data read is: " << buffer.data() << endl;
}
// close file
ifile.close();
}
else
{.....