Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » How to use FileStream?
How to use FileStream? [message #8202] Sun, 18 February 2007 16:42 Go to next message
Ulti is currently offline  Ulti
Messages: 108
Registered: September 2006
Experienced Member
Any example to show how to use Stream class?
my following code result empty file

[I]char data[512];
for(int i=0;i<512;i++) data=0;
MemStream ms(data,512);
header.ToBuf(ms);
CDocFile.Put(data,512);

Re: How to use FileStream? [message #8206 is a reply to message #8202] Sun, 18 February 2007 21:04 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Stream is fully documented, but I guess we could add a couple of detailed examples.

Anyway, your code snippets is too small and undefined. Could you care to post something more substantial?

Mirek
Re: How to use FileStream? [message #8207 is a reply to message #8206] Mon, 19 February 2007 04:15 Go to previous messageGo to next message
Ulti is currently offline  Ulti
Messages: 108
Registered: September 2006
Experienced Member
Sorry,it's my stupid,I just forget to save the buffer into filestream.

but I wonder if my idea is the best one,hope you can give some advice:

I have a buffer which hold 512byte character,and I want save it into file like this way
void CompoundFile::Header::ToBuf(MemStream &buf)
{
buf.Put64le(MagicId);
buf.Put64le(UID1);
buf.Put64le(UID2);
buf.Put16le(rev);
buf.Put16le(ver);
buf.Put16le(byteorder);
buf.Put16le(ssz);
buf.Put16le(sssz);
buf.Put16le(notused1);
buf.Put64le(notused2);
buf.Put32le(SATSecCnt);
buf.Put32le(DirStartSID);
buf.Put32le(notused3);
buf.Put32le(StdStreamSize);
buf.Put32le(SSATStartSID);
buf.Put32le(SSATSecCnt);
buf.Put32le(MSAT1StartSID);
buf.Put32le(MSAT1SecCnt);
buf.Put32le(MSAT1SecCnt);
for(int i=0;i<109;i++)
buf.Put32le(MSAT0[i]);
}
first I put this 512byte into MemStream,and then use the already exist method to write big/little endian,and then put this MemStream into FileStream.
is this is the best way,or any other good ideas(I don't want write any other endian function,they are already in Stream)?


thanks a lot!

[Updated on: Mon, 19 February 2007 04:16]

Report message to a moderator

Re: How to use FileStream? [message #8223 is a reply to message #8207] Tue, 20 February 2007 22:29 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sound quite good, the only complaint I can make is that you probably should use "Stream" instead of "MemStream" to make your method more generic (usable with any Stream derived class you will need in future).

MemStream is very specific Stream kind, with rather limited use.

Mirek
Re: How to use FileStream? [message #8225 is a reply to message #8223] Wed, 21 February 2007 01:01 Go to previous messageGo to next message
Ulti is currently offline  Ulti
Messages: 108
Registered: September 2006
Experienced Member
Thanks Smile
Re: How to use FileStream? [message #8277 is a reply to message #8223] Wed, 28 February 2007 01:39 Go to previous messageGo to next message
Ulti is currently offline  Ulti
Messages: 108
Registered: September 2006
Experienced Member
luzr wrote on Tue, 20 February 2007 16:29

Sound quite good, the only complaint I can make is that you probably should use "Stream" instead of "MemStream" to make your method more generic (usable with any Stream derived class you will need in future).

MemStream is very specific Stream kind, with rather limited use.

Mirek

Steam has the only pure virtual member,is this desired?
Re: How to use FileStream? [message #8282 is a reply to message #8277] Wed, 28 February 2007 09:29 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Ulti wrote on Tue, 27 February 2007 19:39

luzr wrote on Tue, 20 February 2007 16:29

Sound quite good, the only complaint I can make is that you probably should use "Stream" instead of "MemStream" to make your method more generic (usable with any Stream derived class you will need in future).

MemStream is very specific Stream kind, with rather limited use.

Mirek

Steam has the only pure virtual member,is this desired?


Yes. Stream itself does not specificy the "media".

You define your function to work with "Stream", then use specific Stream derived class to store/load from file, memory of whatever.

Mirek
Previous Topic: Problem with Serialization after recompiling with U++ 2007.1beta3
Next Topic: something abaut brc file
Goto Forum:
  


Current Time: Wed Apr 24 17:31:36 CEST 2024

Total time taken to generate the page: 0.04535 seconds