Save the data function
Void Company: : Save (STD: : list
{
Ofstream outfile (" F: \ \ 131 \ \ v \ \ Worker \ \ Worker \ \ Worker \ \ Employee TXT ", the ios: : trunc);
If (outfile. Is_open ())
{
Outfile & lt; & lt; Setw (4) & lt; & lt; "Number" & lt; & lt; Setw (9) & lt; & lt; "Name" & lt; & lt; Setw (9) & lt; & lt; "Age" & lt; & lt; Setw (9) & lt; & lt; "Gender" & lt; & lt; Setw (9) & lt; & lt; "Zip code" & lt; & lt; Setw (9) & lt; & lt; "Department" & lt; & lt; Setw (10) & lt; & lt; "Wages" & lt; & lt; endl;
For (auto it=list. The begin (); it !=list. The end (); It++)
{
Outfile & lt; & lt; * it & lt; & lt; endl;
}
}
Outfile. Close ();
}
CodePudding user response:
Read out the way you writeCodePudding user response:
For (auto it=list. The begin (); it !=list. The end (); It++){
Outfile & lt; & lt; * it & lt; & lt; endl;
}
Here is your class reloading & lt; & lt; Operator, should also be heavy & gt;> Operator, it is ok to read in the same order
CodePudding user response:
How to write in how to read out, the operation differCodePudding user response:
For (auto it=list. The begin (); it !=list. The end (); It++){
Outfile & lt; & lt; * it & lt; & lt; endl;
}
Keep what information, the code is not complete
CodePudding user response:
Class structure can consider binary save and read:Storage using the function, read use read function
Storage:
Ofstream fout (" file ", ios_base: : out | ios_base: : binary);
For (auto it=list. The begin (); it !=list. The end (); It++) {
Fout. Write (char * (* it), sizeof (* it));
}
Read:
Ifstream fout (" file ", ios_base: : out | ios_base: : binary);
The Employee * PTR=new Employee;
Fout. Read (char * (* PTR), sizeof (* PTR));
CodePudding user response:
The building Lord this action is not good, two variables to the output file, the intermediate need a delimiter!!!!!MFC CArchive under reference
CodePudding user response:
Read the file "parse the file to a variableCodePudding user response:
Simple way is to amend the class members to a structure, all use fixed-length data,Written to the file and read out, using the entire structure of the object,
CodePudding user response:
I also have this problem, the core of the problem is, can't like ordinary variables directly read and write the data, the common variables given address directly read came in, but objects are encapsulated, member variables are not directly read, unless the member variables defined as public, but this is not just the destruction of encapsulation?CodePudding user response: