Reading and writing into files

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Guest

Reading and writing into files

Post 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
andrei25ni
Posts: 326
Joined: Wed Dec 14, 2005 10:08 pm

Post by andrei25ni »

same here
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post by Baal Cadar »

What's the specific problem? C++ fstream or the C-file-API not working in some of your cases?
Guest

Post 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
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post 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 ?
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post 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.
kushagra
Posts: 40
Joined: Sun Dec 04, 2005 10:18 am

Post by kushagra »

yeah XML parser is a better option . It is not faster than the binary but more efficiant for saving and loading purposes
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post 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.
Last edited by area51 on Thu Feb 24, 2011 11:54 pm, edited 1 time in total.
Mike
Posts: 17
Joined: Wed Dec 14, 2005 6:42 pm

Post by Mike »

But the question really was how does Irrlicht work with binary files, I would like to know that too.
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post 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.
Post Reply