Page 1 of 1

Help with writing files!

Posted: Fri May 19, 2006 8:25 pm
by Xharock
OK I simply want to write (Create if it doesn't exist) to a file. I have tried using both

Code: Select all

IWriteFile *File;
File->write(WriteBuffer, Size);
and

Code: Select all

IFileSystem *File;
File->createAndWriteFile(Filename, false);
However neither of these methods seem to work and I don't want to have to resort to using C++ File Streams. Can anyone explain step by step if possible how to create and then write to file using Irrlicht?

Posted: Fri May 19, 2006 8:56 pm
by vitek
I could be mistaken, but it looks like you are not very familliar with C/C++ and pointers... You need to initialize the file pointer to refer to a file instance.

Code: Select all

//// assuming that Device is the pointer returned by createDevice()
//// you can replace my constants with variables, but you need to 
//// make sure you initialize each of the pointers...

// get a pointer to the file system
IFileSystem* FileSystem = Device->getFileSystem();

// ask the file system for a pointer to a writable file
IWriteFile* File = FileSystem->createAndWriteFile("blah.txt", false);
if (File)
{
   // write 4 characters to that file
   File->write("blah", 4);

   // destroy the file instance, which should flush the file to disk
   File->drop();
}

Posted: Sat May 20, 2006 9:28 am
by Xharock
You are indeed mistaken. But you learn something new everyday :D

But thanks anyway.

Posted: Sat May 20, 2006 5:14 pm
by vitek
Well, I know that the code I pasted above works. I tested it before posting.

Of course it would help us all if you could explain what happens when you try to write a file with your original code. Does it compile, link, crash, write the file, write garbage, ???

Travis

Posted: Sat May 20, 2006 6:38 pm
by Xharock
It all works now. I have finished my Saving/Loading routines. Thanks for helping.

Posted: Sat May 20, 2006 11:56 pm
by hybrid
I guess by initializing the pointer with correct values :lol: