Skip to main content
GameDev.net gamedev.net
🔒 Locked

Simple Binary File I/O question

Started by henrykl Jul 7, 2013 at 9:55 AM 4 replies 1.7k views
Original Post
henrykl
henrykl

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
JoshuaWaring
JoshuaWaring

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

DareDeveloper
DareDeveloper

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
henrykl
henrykl

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

Bacterius
Bacterius

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.”
DareDeveloper
DareDeveloper

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.