write a union object using write

J

JasBascom

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).
 
J

John Harrison

JasBascom said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Wrapper functions 1
std::sort whole program 2
Short program 3
read problem 6
Is it possible to write an entire server for a non-multiplayer game? 1
function error 6
type conversion 5
union elements 2

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top