I have a list of objects that I would like to save in the file as little as possible for later search. I read this tutorial carefully , and am starting (I think) to understand, but I have a few questions. Here is a snippet I'm working with:
static bool writeHistory(string fileName)
{
fstream historyFile;
historyFile.open(fileName.c_str(), ios::binary);
if (historyFile.good())
{
list<Referral>::iterator i;
for(i = AllReferrals.begin();
i != AllReferrals.end();
i++)
{
historyFile.write((char*)&(*i),sizeof(Referral));
}
return true;
} else return false;
}
Now it is adapted from fragment
file.write((char*)&object,sizeof(className));
taken from a textbook. Now I suppose this does the conversion of the object to a pointer, taking the value and size and writing it to a file. But if so, why do the conversions at all? Why not take value from the start? And why does he need size? Also, from my understanding of why,
historyFile.write((char*)i,sizeof(Referral));
not compile? I am an iterator (and not a pointer iterator?). or simply
historyFile.write(i,sizeof(Referral));
? ? / , , , ?
.txt? <edit> , ? .dtb . </edit> ios:: binary. ( , c_str(), , ).
, ?