Use carchive to access data in VC
1. msdn translation of carchive
The carchive class allows you to save a complex network of objects in a permanent binary form (usually disk storage) that persists after those objects are deleted. later you can load the objects from persistent storage, reconstituting them in memory. this process of making data persistent is called "serialization."
The carchive class allows you to store complex object networks in a permanent binary format (usually in disk storage) and maintain persistence after an object is deleted (the object's lifecycle ends and is destroyed. Then, you can load these objects from persistent storage and rebuild them in the memory. The process of making data persistent is called "serialization"
You can think of an archive object as a kind of binary stream. like an input/output stream, an archive is associated with a file and permits the buffered writing and reading of data to and from storage. an input/output stream processes sequences of ASCII characters, but an archive processes binary object data in an efficient, nonredundant format.
You can think of an archive object as a type of binary stream. Like an input/output stream, an archive is related to a file, allowing data to be written/read to/from memory in a buffer. An input/output stream processes ASCII character sequences, but an archive processes binary object data in an efficient, non-redundant format.
You must create a cfile object before you can create a carchive object. in addition, you must ensure that the archive's load/store status is compatible with the file's open mode. you are limited to one active archive per file.
You must create a cfile object before creating a carchive object. In addition, make sure that the status of the loaded/saved object of the archive object is the same as that of the file opening method. You are limited by the fact that each activity's archive corresponds to a file.
When you construct a carchive object, you attach it to an object of class cfile (or a derived class) that represents an open file. you also specify whether the archive will be used for loading or storing. A carchive object can process not only primitive types but also objects of cobject-Derived classes designed for serialization. A serializable class usually has a serialize member function, and it usually uses the declare_serial and implement_serial macros, as described under Class cobject.
When you construct a carchive object, associate it with the object of the cfile class (or its derived class) to indicate an open file. You can also specify whether archive is used for loading or saving. A carchive object can process not only basic types, but also derived objects of the cobject class (serialized ).
The overloaded extraction (>) and insertion (<) operators are convenient archive programming interfaces that support both primitive types and cobject-Derived classes.
The overload extraction (>) and insertion (<) operators are convenient storage program interfaces. Supports basic types and derived classes of cobject.
2. Use carchive to access files:
Write File:
Cfile file ("1.txt", cfile: modecreate | cfile: modewrite );
Carchive AR (& file, carchive: Store );
Int I = 333;
Float F = 1.3333f;
Char CH = 'V ';
Ar <I <F <ch;
Read files:
Cfile file ("1.txt", cfile: moderead );
Carchive AR (& file, carchive: load );
Int I;
Float F;
Char ch;
Cstring strresult;
Ar> I> F> CH;
Strresult. Format ("% d, % F, % C", I, F, CH); // format the output data
MessageBox (strresult); // display read data
Post: http://blog.pfan.cn/bclz/26883.html