Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstdlib>
- #include <string>
- #include <fstream>
- using namespace std;
- struct base
- {
- string day;
- string month;
- string year;
- };
- int main()
- {
- const char* FName = "1.txt";
- vector <base> s;
- base b;
- base d;
- cout<<"1. Vvedite dlya 1 dati:"<<endl;
- cout<<"Day:";
- cin>>b.day;
- cout<<"Month:";
- cin>>b.month;
- cout<<"Year:";
- cin>>b.year;
- cout<<"2. Vvedite dlya 2 dati:"<<endl;
- cout<<"Day:";
- cin>>d.day;
- cout<<"Month:";
- cin>>d.month;
- cout<<"Year:";
- cin>>d.year;
- s.push_back(b);
- s.push_back(d);
- ofstream out(FName, ios::binary); //Ставим режим "бинарный файл"
- out.write((char*)&s, sizeof(s)); //Записываем в файл значение "x"
- //out.write((char*)&d, sizeof(d)); //Записываем в файл значение "y"
- out.close();
- ifstream in(FName,ios::binary);
- in.read((char*)&s, sizeof(s)); //перенос байтов из файла в "х"
- //перенос байтов из файла в "y"
- in.close();
- /*КОНЕЦ РАБОТЫ С ФАЙЛОМ*/
- string line;
- ifstream as(FName);
- if (as.is_open()) while (getline(as,line)) cout << line;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement