-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadObject.cpp
More file actions
79 lines (73 loc) · 1.57 KB
/
readObject.cpp
File metadata and controls
79 lines (73 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* =====================================================================================
*
* Filename: readObject.cpp
*
* Description: Store Object in Binary File
*
* Version: 1.0
* Created: 03/06/2013 07:32:02 PM
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include <fstream>
#include <iostream>
#include <stdlib.h>
using namespace std;
/*
* === FUNCTION ======================================================================
* Name: main
* Description: Create object
* =====================================================================================
*/
class MSC{
private:
int m;
float j;
public:
MSC(int p = 1,float q = 1.0 ){
m = p;
j = q;
}
void display() const {
cout<<" m = "<<m<<endl;
cout<<" j = "<<j<<endl;
}
void adder() {
m += 1;
j += 1.0;
}
void store (ostream & fout){
fout.write((char *) this , sizeof(*this));
}
void retrive( ifstream & fin){
fin.read((char *) this ,sizeof(this));
}
};
int
main ( int argc, char *argv[] )
{
cout<<"Binary I/O for object "<<endl;
MSC a(2 , 3.0);
ofstream fout("MyFile1");
cout<<"Store Object "<<endl;
a.store(fout);
a.display();
ifstream fin("MyFile1");
if(fin == NULL){
cout<<"File Error"<<endl;
exit(0);
}
while ( !fin.eof() ){
cout<<"In Loop "<<endl;
a.display();
a.retrive(fin);
}
fin.close();
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */