When I search this topic, I find a lot of examples of how to correctly access a binary file using std::fstream
. I lifted a snippet and it compiles fine (Visual Studio 2017). However, at runtime (this code is within a DLL), the file doesn't seem to open. I am assuming the file doesn't have to be *.bin
or something to work... is that correct? I can't think of what else is going off the rails. The reading into a buffer stuff is probably wrong - I can't even get to that part yet.
std::fstream binaryFile;
binaryFile.open(cdgName, std::ios::binary);
if (binaryFile.good())
{
BYTE i[24];
while (binaryFile >> i)
{
//handle
}
binaryFile.close();
} else
{
MessageBoxA(NULL, cdgName, "File Error!", MB_OK);
}
When I try this, the MessageBox
shows. FYI, the window contains the file path (cdgName
) and it is "C:\Users\Rick\Music\America - You Can Do Magic.cdg"
, which is a valid file. I also have tried .is_open()
instead of .good()
. I have tried variations with ifstream
and using the ::ios::in
flag - not knowing exactly what I am doing - which caused errors at run.