Answer the question
In order to leave comments, you need to log in
Why doesn't C++ ifstream::read read the entire binary file?
Hello!
I ran into a problem when working with a binary file in C++.
Here is a code snippet:
//! Get memory to File
bool MemFromFile(const char * strFileName, std::vector<char> &DataOut)
{
DataOut.clear(); // clearing data in vector for add new data
std::ifstream inFile(strFileName); // open file
if(!inFile.is_open())
return false; // Can't create or read file
do
{
char Buf = '\0';
if (inFile.read(&Buf, 1))
DataOut.push_back(Buf);
} while (inFile);
inFile.close(); // close file
return true;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question