Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct Book
- {
- char genre;
- char author[30];
- int page;
- char title;
- };
- void createBINFILE(ifstream& f, ofstream& g)
- {
- Book x;
- while (f>>x.genre>>x.author>>x.page>>x.title)
- {
- g.write((char*)&x, sizeof(Book));
- }
- }
- void functionOtbor(ifstream& f)
- {
- Book x;
- int g; //1 - детектив //2 - фантастика //3- роман
- cout << "Выберите жанр\n";
- cout << "1 - детектив 2 - фантастика 3 - роман = ";
- cin >> g;
- switch (g)
- {
- case 1:
- while (f.peek()!=EOF)
- {
- f.read((char*)&x, sizeof(Book));
- if (x.genre == 'd')
- {
- cout << x.author << " " << x.page << "\n";
- }
- }
- break;
- case 2:
- while (f.peek() != EOF)
- {
- f.read((char*)&x, sizeof(Book));
- if (x.genre == 'f')
- {
- cout << x.author << " " << x.page << "\n";
- }
- }
- break;
- case 3:
- while (f.peek() != EOF)
- {
- f.read((char*)&x, sizeof(Book));
- if (x.genre == 'n')
- {
- cout << x.author << " " << x.page << "\n";
- }
- }
- break;
- }
- }
- int main()
- {
- setlocale(LC_ALL, "RU");
- ifstream intxt("book.txt");
- ofstream outbin("booksbin.bin", ios::binary);
- createBINFILE(intxt, outbin);
- intxt.close();
- outbin.close();
- ifstream inbin("booksbin.bin", ios::binary);
- functionOtbor(inbin);
- inbin.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment