Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > write a union object using write

Reply
Thread Tools

write a union object using write

 
 
JasBascom
Guest
Posts: n/a
 
      02-24-2004
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).



 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      02-24-2004

"JasBascom" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
struct or class object with constructor in UNION flags as error. !! iceColdFire C++ 4 05-06-2005 10:18 AM
union in struct without union name Peter Dunker C Programming 2 04-26-2004 07:23 PM
map XML union to C union (and vice-versa) Matt Garman XML 1 04-25-2004 12:40 AM
What is the purpose of using UNION in a class...?? jonnychang C++ 4 06-27-2003 11:03 PM



Advertisments