Advertisement
Uncleeee

Untitled

Apr 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdlib>
  4. #include <string>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. struct base
  10. {
  11. string day;
  12. string month;
  13. string year;
  14. };
  15.  
  16. int main()
  17. {
  18. const char* FName = "1.txt";
  19.  
  20. vector <base> s;
  21. base b;
  22. base d;
  23.  
  24. cout<<"1. Vvedite dlya 1 dati:"<<endl;
  25.  
  26. cout<<"Day:";
  27. cin>>b.day;
  28.  
  29. cout<<"Month:";
  30. cin>>b.month;
  31.  
  32. cout<<"Year:";
  33. cin>>b.year;
  34.  
  35. cout<<"2. Vvedite dlya 2 dati:"<<endl;
  36. cout<<"Day:";
  37. cin>>d.day;
  38.  
  39. cout<<"Month:";
  40. cin>>d.month;
  41.  
  42. cout<<"Year:";
  43. cin>>d.year;
  44.  
  45. s.push_back(b);
  46. s.push_back(d);
  47.  
  48. ofstream out(FName, ios::binary); //Ставим режим "бинарный файл"
  49. out.write((char*)&s, sizeof(s)); //Записываем в файл значение "x"
  50. //out.write((char*)&d, sizeof(d)); //Записываем в файл значение "y"
  51. out.close();
  52. ifstream in(FName,ios::binary);
  53. in.read((char*)&s, sizeof(s)); //перенос байтов из файла в "х"
  54. //перенос байтов из файла в "y"
  55. in.close();
  56. /*КОНЕЦ РАБОТЫ С ФАЙЛОМ*/
  57.  
  58. string line;
  59. ifstream as(FName);
  60. if (as.is_open()) while (getline(as,line)) cout << line;
  61.  
  62.  
  63. system("pause");
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement