Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)
I know basically nothing about writing to files what should I do
staffMember is a base class it has two derived classes inheriting from it all three of them are linked via agregation to the class company _allEmployees is a vector of pointers to staffmembers <staffMember*> which represents a list of all the staff members currently held by company what I am trying to do is save this list so that it is possible to load the information the next time the program is run
first of all: please, give me some air! one or two periods from time to time won't hurt! ;)
Now, your explanation is a bit confusing, cause staffMember can't be a class and a list of all the staff members at the same time... I guess IN staffMember, there is a kind of container with all the staff members. Could you post the definition of staffMember class?
staffMember is a class and nothing more _allEmployees is the list. the list is made up of staffMember objects or more precicely pointers to staff member objects. there is nothing wrong with the staffMember class or the list all I need to know is the correct syntax for saving a vector to a file
because
staffMember is an empty class? why on earth would you want an empty class? you need to store the names of the staff, then you do a vector <string> _allEmployees;
Well, perhaps I'm missing something. Anyway, to understand the syntax working with files: myfile is a fstream -> file stream. It works exactly as if you were working with iostream, i. e. as you were using "cout <<", but instead of you monitor, the receiver is the text file. of course, you cannot output "a class", or a pointer to a class, but rather "a variable" stored in the class.
You don't "save a vector" to a file, you write the content of the vector in a file. Vector is a container, therefore you can't "<< _allEmployees", but rather
1 2 3
for (int n = 0; n <_allEmployees.size(); n++){
myfile << _allEmployees [n].myVariable <<endl;
}
it compiles fine that line simply says that the pointer sta has the values from position i in the vector _allEmployees I found the text file it wrote perfectly.
one more question would this method that I have used work for writeing to other types of file, for example a comma separated values file (.csv)