Writing to/loading from a file (VECTOR).

May 29, 2012 at 3:00pm
Hi there.
I have a vector
vector<Worker> workers;

and a class
1
2
3
4
5
6
7
8
9
class Worker
{
    private:
        string name;
        myownenumtype something;
        myownenumtype2 something2;
    public:
        ...
}
and I am struggling with how to write elements in the vector into a txt file and how to load them from it. Could you be so kind to help me with it?
Greetings.
Last edited on May 29, 2012 at 3:00pm
May 29, 2012 at 6:11pm
Hi
There might be 100 different solutions to your problem, I am not giving you some code, instead some steps :- >

1- learn how you can read and write from/into file -> http://www.cplusplus.com/reference/iostream/fstream/
2- define a format for your output file where you can write your data, i.g, how should be the data (vector of type Worker) organised/set in the file
3- define a way to read the data from file( this step depends on step-2)
4- define a how way how you stored the data read from file into target vector
Topic archived. No new replies allowed.