Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <list>
- using namespace std;
- class Hospital {
- public:
- string doctor_name;
- string patient_name;
- string patient_diagnos;
- int num_palata;
- Hospital() {
- doctor_name = patient_name = patient_diagnos = num_palata = 0;
- }
- Hospital(string doctor_name, string patient_name, string patient_diagnos, int num_palata) {
- this->doctor_name = doctor_name;
- this->patient_name = patient_name;
- this->patient_diagnos = patient_diagnos;
- this->num_palata = num_palata;
- }
- void Print() {
- cout << "doctor_name: " << doctor_name << "\tpatient_name: " << patient_name << "\tpatient_diagnos: " << patient_diagnos << "\tnum_palata: " << num_palata << endl;
- }
- friend ostream& operator << (ostream& f, const Hospital& i)
- {
- return f << "doctor_name: " << i.doctor_name << "\tpatient_name: " << i.patient_name << "\tpatient_diagnos: " << i.patient_diagnos << "\tnum_palata: " << i.num_palata;
- }
- private:
- static void readStr(string& s, istream& f)
- {
- size_t l;
- f.read((char*)&l, sizeof(size_t));
- char* str = new char[l + 1];
- f.read(str, l);
- str[l] = 0;
- s = str;
- delete[] str;
- }
- };
- static void SortByPatientName(list<Hospital>& list) {
- list.sort([](Hospital& l1, Hospital& l2) { return l1.patient_name < l2.patient_name; });
- }
- void Write(string path) {
- string doctor_name, patient_name, patient_diagnos, num_palata;
- //cin >> doctor_name;
- //cin >> patient_name;
- //cin >> patient_diagnos;
- //cin >> num_palata;
- Hospital bf("d", "4", "4", 4);
- //bf.Print();
- ofstream fout;
- fout.open(path, ofstream::app);
- if (!fout.is_open())
- {
- cout << "Error open!" << endl;
- }
- else {
- fout.write((char*)&bf, sizeof(Hospital));
- }
- fout.close();
- }
- void Read(string path) {
- list<Hospital> l;
- ifstream fin;
- fin.open(path);
- if (!fin.is_open())
- {
- cout << "Error open!" << endl;
- }
- else {
- Hospital b;
- while (fin.read((char*)&b, sizeof(Hospital)))
- {
- l.push_back(b);
- }
- for (auto i : l)
- i.Print();
- //SortByPatientName(l);
- //cout << endl;
- //for (auto i : l)
- // i.Print();
- }
- fin.close();
- }
- int main()
- {
- string path = "text.txt";
- Write(path);
- cout << "12";
- Read(path);
- int log;
- cout << "12";
- cin >> log;
- cout << "12";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment