|
-
March 31st, 2011, 03:29 PM
#6
Re: Reading a File
Read and Write must mirror each other. Write sets the file format, Read must be able to read the same format. This class test now knows how to write itself to an ostream and read from an istream. The nonmember operators are called in for instance...
cout << test1;
This calls operator << ( cout, test1) which calls test1.Write( cout ) which places each member into the stream separated by in this example the '/' char and a newline at the end of each test written. I should have used '\n' instead of endl as endl causes a stream flush but the point was to show you how to structure simple serialisation of classes.
Get Microsoft Visual C++ Express here or CodeBlocks here.
Get STLFilt here to radically improve error messages when using the STL.
Get these two can't live without C++ libraries, BOOST here and Loki here.
Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
Always use [code] code tags [/code] to make code legible and preserve indentation.
Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|