The file needs to be established in the operating system, and in accordance with the above format manual entry several records, programs corresponding data read from the file first, and then complete the above function
#include
#include
#include
#include
using namespace std;
The class the Teacher//declare the Teacher class
{public:
The Teacher () {}
The Teacher (string nam, int a, char s, a string of AD, string t, string tit) : name (nam), age (a), sex (s), addr (AD), tel (t), title (tit) {}
Void the display ();
Protected:
String name;
int age;
char sex;
String addr.
String tel;
String title;
};//the Teacher class member function definition of
Void the Teacher: : display ()
{cout<" Name: "& lt;
The class Cadre//statement class Cadre
{public:
Cadre () {}
Cadre (string nam, int a, char s, a string of AD, string t, string tit, string p) : name (nam), age (a), sex (s), addr (AD), tel (t), title (tit), post (p) {}
Void the display ();
Protected:
String name;
int age;
char sex;
String addr.
String tel;
String title;
The string post;
};//Cadre class member function definition of
Void Cadre: : display ()
{cout<" Name: "& lt;
Class Teacher_Cadre: public the Teacher, public Cadre//declare multiple utility derived class Teacher_Cadre class
{public:
Teacher_Cadre ()
{
}
Teacher_Cadre (string nam, int a, char s, a string of AD, string t, string tit, string p, float w) : the Teacher (nam, a, s, AD, t, tit), Cadre (nam, a, s, AD, t, tit, p), wages (w) {}
Void the show ();
Private:
Float wages;
};
Void Teacher_Cadre: : show ()
{the Teacher: : display ();//specify the domain
Cout<" Post: "& lt;
Int main ()
{void save_to_file ();
Void get_from_file ();
Teacher_Cadre te_ca (39, "Wang", "f", "QingNianDaJie", "0245656896", "JAVA" and "President", 5738.0);
Te_ca. The show ();
Save_to_file ();
Get_from_file ();
system("pause");
return 0;
}
Void save_to_file ()
{ofstream outfile (" Teacher_Cadre. TXT ", the ios: : out);
if(! Outfile)
{cerr<" The open error!"
}
Outfile<" Wang "& lt;
}
Void get_from_file ()
{ifstream infile "Teacher_Cadre. TXT", the ios: : (in);
if(! Infile)
{cerr<" The open error!"
}
Infile. Close ();
}