Crystal Space
Welcome, Guest. Please login or register.
September 19, 2014, 07:01:36 am

Login with username, password and session length
Search:     Advanced search
9018 Posts in 2051 Topics by 8481 Members
Latest Member: Cex18145xu
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  General Crystal Space Discussion
| | |-+  How to binary-read a file on VFS?
« previous next »
Pages: [1] Print
Author Topic: How to binary-read a file on VFS?  (Read 2422 times)
kornerr
Full Member
***
Posts: 101


347968356
View Profile WWW Email
« on: July 04, 2006, 12:40:15 pm »

i need to rewrite this in VFS:
Code:
    FILE *f;
    f = fopen (filename, "rb");
    if (f == NULL)
        return false;
    fread (&version, sizeof (TBXVersion), 1, f);
so i tried this:
Code:
    csRef<iVFS> vfs;
    vfs = csQueryRegistry<iVFS> (obj_reg);
    csRef<iFile> f = vfs->Open (filename, VFS_FILE_READ);
    f->Read (version, sizeof (TBXVersion));
but i get errors:
Code:
tbx.cpp: In member function `bool TBXFile::Open(char*)':
tbx.cpp:14: error: no matching function for call to `iFile::Read(TBXVersion&,
   unsigned int)'
/usr/local/include/crystalspace/iutil/vfs.h:134: error: candidates are: virtual
   size_t iFile::Read(char*, unsigned int)
make: *** [obj/tbx.o] Error 1
so how to read structures?

thanks.
Logged

jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #1 on: July 28, 2006, 12:04:22 pm »

Note that in general you should avoid to read binary structures as that is highly unportable. But if you really want to do it I recommend you take a look at the iFile API. There are methods there to read data in a buffer which you can then copy to the structure.

Greetings,
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 6.25 seconds with 15 queries.