using fstream with 'binary' flag, same results as w/o 'binary' flag

Hello, I hope this is in the right section, anyhow i was trying to write a program that acts more of a database(using IPC and binary files to read/write tables/columns/rows) and I have 3 structs, which contain arrays.. anyway I wrote it all up in the file and added a header for sizes, problem is with or without 'binary' flag, i still get the same output in the file
#Test 1(with binary flag):
_ FooTable BarColumn MyColumn  BarColumnNULL MyColumnNULL
#Test 2(without binary flag):
_ FooTable BarColumn MyColumn  BarColumnNULL MyColumnNULL
Same output..
I write the size of the whole table struct as a header for the file, which i print on the console when writing the file, i got the size of 92, except when trying to load the file, loading the size header returns -11172624(not exact but it was a huge number lol), of course causing other flaws because i should use the size header to read all of the other data saved, ex. bad_allocation exception.

May anyone please help a desperate programmer? I'm totally lost here
.
P.S If someone asks for a code sample i'd be glad to provide, just thought this might not need any code samples as the problem is with the file itself..
The only difference between binary and text mode is that when opening for text, newlines are translated from their native form, depending on platform, to linefeed characters ('\n').
Windows:
"\r\n" -> "\n"
Mac:
"\r" -> "\n"
UNIX:
No change.
Binary mode doesn't do this.
Oh, and under text mode, the file stops being read when the first EOF character (0xFF, IIRC) is found.

Other than that, binary mode will not help you process the file at all. You have to do it yourself.
The garbage number part is probably an endianness problem. I suggest you read this: http://en.wikipedia.org/wiki/Endianness
Thanks for the reading material, so basically doing it anyway(binary or text) won't matter much(considering that i never write newlines)?
considering that i never write newlines
Since the file is binary, there's no telling what could be in it. You should always default to open everything as binary, and open only as text when you're absolutely certain nothing will be lost (quite rare, actually. The most common purpose is reading configuration files).
I don't know why the designers of C decided to make text the default mode for opening files, but here we are.
Last edited on
Okay, I ran a test run for my stream writing class and it looks like it stores values backwards, i wrote 2 ints in a stream in this order(First int: 8, Second int: 400) when reading it, it returned (First int: 400, Second int: 8)
I'll try to fix this up


Error: Wrong path(file does not exist)
Last edited on
Topic archived. No new replies allowed.