472,145 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

write a union object using write

if validdata is a ifstream object of mode type binary.

ifstream validdata;
fstream sortfile;

how would I read a union.

union Allrecords *rec;

validdata.write()

how would i write this to the sortfile, sortfile is a text file (.txt).

Jul 22 '05 #1
1 1346

"JasBascom" <ja*******@aol.com> wrote in message
news:20***************************@mb-m02.aol.com...
if validdata is a ifstream object of mode type binary.

ifstream validdata;
fstream sortfile;

how would I read a union.

union Allrecords *rec;
That's not a union, its a pointer to a union.

Assuming you have made rec point to a suitable piece of memory (I remember
you making this mistake before) then

validdate.read(rec, sizeof *rec);

will read a single record into the union pointed to by rec.

validdata.write()

Write? I though you were trying to read (that also was something you were
confused about earlier).
how would i write this to the sortfile, sortfile is a text file (.txt).


There is no simple way to write a union to a text file. It all depends on
exactly what you want to write. You have to decide how you want to write it
and use << appropriately. For more advice post the definition of Allrecords
and say precisely how you want the data to appear, i.e. what is to be
written under what circumstances, where spacing is needed, where newlines
are needed etc. etc.

john
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ann Huxtable | last post: by
6 posts views Thread by Neil Zanella | last post: by
2 posts views Thread by Peter Dunker | last post: by
18 posts views Thread by ranjeet.gupta | last post: by
16 posts views Thread by tedu | last post: by
8 posts views Thread by wkaras | last post: by
1 post views Thread by forey | last post: by
10 posts views Thread by piboye | last post: by
30 posts views Thread by Yevgen Muntyan | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.