Connecting Tech Pros Worldwide Help | Site Map

write a union object using write

  #1  
Old July 22nd, 2005, 07:48 AM
JasBascom
Guest
 
Posts: n/a
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).



  #2  
Old July 22nd, 2005, 07:49 AM
John Harrison
Guest
 
Posts: n/a

re: write a union object using write



"JasBascom" <jasbascom@aol.com> wrote in message
news:20040223232248.12245.00000330@mb-m02.aol.com...[color=blue]
> if validdata is a ifstream object of mode type binary.
>
> ifstream validdata;
> fstream sortfile;
>
> how would I read a union.
>
> union Allrecords *rec;[/color]

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.
[color=blue]
>
> validdata.write()
>[/color]

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

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


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing literals to union arguments Richard Harter answers 29 July 30th, 2007 05:15 PM
Problem with wrapping an unmanaged C++ DLL using the header file Lokkju answers 0 November 17th, 2005 03:18 PM
union initializers idiosyncrasies Neil Zanella answers 6 November 13th, 2005 07:05 PM
segmentation fault on delete object (which belongs to some class under a hierarchy) Joel answers 4 July 22nd, 2005 09:21 PM