CLASSES AND FILES

how can i store the private members of a classs in a data file (using fstream)
You need a member-function that returns the value of the members.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class myClass
{ int myInt;
// this is the function you will need
   int get_myInt(){return myInt];
]

int main()
{// blabla
    myClass Example_class;
    int temp_for_storage; 
    temp_for_storage = Example_class.get_myInt();
 // code to store the value

}


Of course, a vector of classes would be better since you can iterate through the classes with a loop. But the concept of retrieving values remains the same.
int main
Topic archived. No new replies allowed.