Connecting Tech Pros Worldwide Help | Site Map

write a union object using write

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 06:48 AM
JasBascom
Guest
 
Posts: n/a
Default 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).




  #2  
Old July 22nd, 2005, 06:49 AM
John Harrison
Guest
 
Posts: n/a
Default 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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.