Simple Binary File I/O question

Started by
4 comments, last by DareDeveloper 10 years, 9 months ago

I am currently writing a Maya exporter. i already got it working in .xml format but im trying to port it over to a binary file.

When I try to create the binary file it always fails. Any Ideas on why this might be:

string path = writeOutMesh.m_strName + ".mesh";
std::ofstream BinOut;
BinOut.open(path.c_str(),std::ios_base::binary | std::ios_base::trunc);
if( !BinOut.is_open() )
return;
It always hits the return.
Any help will be much appreciated
Thanks
Advertisement

try adding std::ios_base::out
to your arguments

According to the documentation it is automatically set ... so that shouldn't be it.

Have you logged if BinOut.fail() returns true? If it does not it must be something stupid. Have you tried writing to it before you check if it is open?

How different is the code from the XML version? Just the binary flag and ".xml" to ".mesh"? Or was the xml file called ".mesh" as well (not that it matters much)?

Given enough eyeballs, all mysteries are shallow.

MeAndVR

Yes, for the most part the code is the same minus the binary flag and the ".mesh". And yes the BinOut does fail

Can you print out the path.c_str() for debugging purposes? Otherwise I really can't see anything wrong from here, especially if it worked fine before in text mode.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Maybe the file is open and blocked by another program? Would be weird in the case of the binary file, I guess.

You might be missing something if you are looking at the wrong directory. Happened to me a few fimes when I changed output folders in project settings.

Must be something on the file system level ... I too don't see anything wrong with the code.

Have you watched the folder while the program is executed? Have you created the file by hand before running the executable?

Given enough eyeballs, all mysteries are shallow.

MeAndVR

This topic is closed to new replies.

Advertisement