I've got 4 c++ books and a reference book, but they still leave a lot to be desired. For some reason, I/O is just not covered very well. I've also been googling but haven't found all the answers I need yet.
I have a structure with 2 char arrays and an integer. What I'm trying to do is learn all the ways this structure can be written to a file.
I first tried the following example without the 'endl' commands but it wrote all the data on one line. I had expected ofstream to read and include the null terminators in the char arrays, but it doesn't? So I added them myself and it seemed to work fine.
Code:
outfile << rec.first << endl << rec.second << endl << rec.num;
I've also read some about write() and put(). Are these the only 3 methods available?
And could you give me a small example of how I would write the structure with write() and put() and which one of the 3 is preferable in various situations? Thanks.