Page 1 of 1

Reading and writing into files

Posted: Tue Jan 10, 2006 4:14 pm
by Guest
I want to read and write following things to a binary file , how can i do so
1. wchar strings
2. f32 type
3. u32 type

plz can anybody tell me the proper method to handle files in above cases
thank u

Posted: Tue Jan 10, 2006 6:17 pm
by andrei25ni
same here

Posted: Tue Jan 10, 2006 6:33 pm
by Baal Cadar
What's the specific problem? C++ fstream or the C-file-API not working in some of your cases?

Posted: Tue Jan 10, 2006 8:01 pm
by Guest
i used this function

irr::io::IWriteFile *fwrite = device->getFileSystem()->createAndWriteFile("hello.dat", false);

and i opened my directory and there wz no file named "hello.dat"

the programmed ran correctly but why there is no file created
I m usin vc++ 2005

Posted: Wed Jan 11, 2006 1:47 am
by krama757
Did you try to write to the file? Maybe you need to write something for it to be created.

If you dont want to use the irrlict interface, then why not use fstream.h ?

Posted: Wed Jan 11, 2006 6:00 pm
by pfo
I don't think Irrlicht's file API will actually commit the contents to disk until the pointer is dropped. I recomend staying away from a binary file format or something that can be confusing, try something like TinyXML or Irrlicht's built in XML parser.

Posted: Thu Jan 12, 2006 6:51 am
by kushagra
yeah XML parser is a better option . It is not faster than the binary but more efficiant for saving and loading purposes

Posted: Thu Jan 12, 2006 12:16 pm
by area51
If you're trying to Save/Load a game, then the best way, IMO is to serialize the game's state object(s) to disk.

If it's for a config/ini/help file type thing, then I agree, XML is better.
________
BREWSTER & CO.

Posted: Fri Jan 13, 2006 8:21 pm
by Mike
But the question really was how does Irrlicht work with binary files, I would like to know that too.

Posted: Fri Jan 13, 2006 9:09 pm
by pfo
But the question really was how does Irrlicht work with binary files, I would like to know that too.
The same way every application deals with binary files, by recreating the data. To write a string to a binary file, one method is to get the length of the string and then save those characters like {3pfo} in the binary file. f32 is just a float, you can write it right into the file, u32 is an unsigned int, again, can be written right into the file. When you read the binary data back in, you need to know what elements are stored in what order to read it correctly.