Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Hotel::Read(Hotel &hotel)
- {
- ifstream file;
- string buff;
- file.open("save_file.csv", ios::in);
- n = 0;
- file >> buff;
- if (!file.is_open()){
- cout << "(!) File doesn't exist!\nCreate it? [Y/N]\n" << endl;
- cout << "~ ";
- string create_file; cin >> create_file;
- if (create_file == "Y"||create_file == "y"
- ||create_file == "Р”"||create_file == "Рґ")
- { ofstream file;
- file.open("save_file.csv", ios::out);
- cout << "(!) File created!" << endl;}
- else cout << "Creating aborted..." << endl;
- file.close();
- }
- else {
- if (buff.empty())
- cout << "(!) File is empty..." << endl;
- else {
- ifstream file;
- file.open("save_file.csv", ios::in);
- while (!file.eof())
- {
- string s_id = std::to_string(id); /* all to str */
- string s_cost = std::to_string(cost);
- string s_name(name);
- string s_fname(fname);
- string s_date_1(date_1);
- string s_date_2(date_2);
- string s_phoneNumber(phoneNumber);
- std::getline(file, s_id, ';');
- std::getline(file, s_name, ';');
- std::getline(file, s_fname, ';'); /*Read from csv*/
- std::getline(file, s_date_1, ';');
- std::getline(file, s_date_2, ';');
- std::getline(file, s_phoneNumber, ';');
- std::getline(file, s_cost, ';');
- id = atoi(s_id.c_str()); /*str to int*/
- cost = atoi(s_cost.c_str());
- const char *r_name = s_name.c_str(); /*str to char*/
- strcpy(name, r_name); /*const char to char*/
- const char *r_fname = s_fname.c_str();
- strcpy(fname, r_fname);
- const char *r_date_1 = s_date_1.c_str();
- strcpy(date_1, r_date_1);
- const char *r_date_2 = s_date_2.c_str();
- strcpy(date_2, r_date_2);
- const char *r_phoneNumber = s_phoneNumber.c_str();
- strcpy(phoneNumber, r_phoneNumber);
- lst.Add(hotel);
- n++;
- }
- cout << "\n\t(!) Reading successfully! Objects: " << n <<".\n\t\tOpened: save_file.csv" << endl;
- }
- }
- file.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement