#include #include #include using namespace std; //#include class A { private: int a; int b; int *ptr; string name; public: A():a(10),b(20){ptr=NULL;} A(int x,int y):a(x),b(y){ptr = new int;*ptr = 100; } ~A() {delete ptr;} void setname(string str){name = str;} int geta(){return a;} int getb(){return b;} string getname(){return name;} }; int main() { // char *str, *str2; int t=10; int *ptr = &t; int *&rp=ptr; string name; char str[5]; A aobj(12,14); A ao; ofstream fo("file.txt",ios_base::out); ifstream fi; cin>>name; aobj.setname(name); cout << "writing into file"; int a; a = aobj.geta(); int *p; p = &a; fo<< aobj.getname();//<<(char *)aobj.getb()<<(char *)aobj.getname(); fo.close(); fi.open("file.txt",ios_base::in); fi.read(str,4); str[4]='\0'; cout< using namespace std; class Date { //... virtual ofstream& Write(ofstream& archive); virtual ifstream& Read(ifstream& archive); }; ofstream& Date::Write(ofstream& archive) //ANSI/ISO C++ Professional Programmer's Handbook - Chapter 14 - Concluding Remarks and Future Directions //file:///D|/Cool Stuff/old/ftp/1/1/ch14/ch14.htm (8 von 18) [12.05.2000 14:46:48] { archive.write( reinterpret_cast (&day), sizeof(day)); archive.write( reinterpret_cast (&month), sizeof(month)); archive.write( reinterpret_cast (&month), sizeof(year)); return archive; } ifstream& Date::Read(ifstream& archive) { archive.read( reinterpret_cast (&day), sizeof(day)); archive.read( reinterpret_cast (&month), sizeof(month)); archive.read( reinterpret_cast (&month), sizeof(year)); return archive; } In addition to the member functions Read() and Write(), it is necessary to define a reconstituting constructor, which reads a serialized object from a stream: Date::Date(ifstream& archive) //reconstituting constructor { Read(arcive); } #endif