it enables you to put any data type out to the file, including your own home-baked ones... for example:
Code:
//use iostream for standard console I/O
#include <iostream>
//use fstream for standard file I/O
#include <fstream>
//use cctype for strlen
#include <cctype>
struct myStruct
{
char*line;
int letters;
};
int main()
{
//declare a variable to write to the file
myStruct A;
//fill in the struct with some dummy data
A.line="Hello World";
A.letters=strlen(A.line);
//open the file for binary reading and writing
std::fstream file("test.in",std::ios::in|std::ios::out|
std::ios::trunc|std::ios::binary);
//write the char to the file (note the cast and sizeof method)
file.write(reinterpret_cast<char*>(&A),sizeof(A));
//reset the 'read' or 'get' pointer to the beginning of the file
file.seekg(0,std::ios::beg);
//read from the file (again note the cast and sizeof)
file.read(reinterpret_cast<char*>(&A),sizeof(A));
//close the file
file.close();
//output the character read from the file
std::cout<<A.line<<std::endl<<A.letters<<std::endl;
//end the program
return 0;
}