Help with writing files!

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Xharock
Posts: 71
Joined: Wed May 10, 2006 3:50 pm

Help with writing files!

Post 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?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post 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();
}
Xharock
Posts: 71
Joined: Wed May 10, 2006 3:50 pm

Post by Xharock »

You are indeed mistaken. But you learn something new everyday :D

But thanks anyway.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post 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
Xharock
Posts: 71
Joined: Wed May 10, 2006 3:50 pm

Post by Xharock »

It all works now. I have finished my Saving/Loading routines. Thanks for helping.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I guess by initializing the pointer with correct values :lol:
Post Reply