Pandarec13

source(Students).cpp

Nov 14th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include "Students.h"
  4. #include <string>
  5.  
  6. using namespace std;
  7. int main() {
  8. setlocale(LC_ALL, "");
  9.  
  10. string ch;
  11. Student pers; // создать объект person
  12.  
  13. fstream file; // создать входной/выходной файл
  14. // открыть для дозаписи
  15. file.open("student.dat", ios::app | ios::out |
  16. ios::in | ios::binary);
  17. do // данные от пользователя - в файл
  18. {
  19. cout << "\nВведите данные о человеке:" << endl;
  20. cout << endl;
  21. //pers.getdata(); // получить данные
  22. // записать их в файл
  23. pers = inputStud();
  24.  
  25. file.write(reinterpret_cast<char*>(&pers), sizeof(pers));
  26. cout << "Продолжить ввод (no/yes)? "<<endl;
  27. cin >> ch;
  28. if (ch != "no" && ch != "yes") {
  29. while (ch != "no" && ch != "yes") {
  30. cout << "введен не корректный ответ. Повторите попытку : ";
  31. cin >> ch;
  32. cout << endl;
  33. }
  34. }
  35. } while (ch !="no"); // выход по 'n'
  36. file.seekg(0); // поставить указатель на начало файла
  37. // считать данные о первом человеке
  38. file.read(reinterpret_cast<char*>(&pers), sizeof(pers));
  39. while (!file.eof()) // Выход по EOF
  40. {
  41. cout << "\nПерсона:";// вывести данные
  42. outStud(pers);
  43. file.read(reinterpret_cast<char*>(&pers), sizeof(pers));
  44. }
  45. cout << endl;
  46.  
  47.  
  48.  
  49. system("pause");
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment