Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <clocale>
- using namespace std;
- struct word {
- int key;
- string engWord;
- string rusWord;
- };
- void reWrite(ifstream &iF, ofstream &oFB);
- void readBin(ifstream &iFB);
- void search(ifstream &iFB, word *arrWord, int &count);
- int main()
- {
- setlocale(LC_ALL, "RUS");
- ifstream iF("Dictionary.txt", ios::in);
- ofstream oFB("BinDictionary.txt", ios::binary|ios::out);
- if (iF && oFB)
- {
- reWrite(iF, oFB);
- ifstream iFB("BinDictionary.txt", ios::binary | ios::in);
- if (iFB)
- readBin(iFB);
- //
- //int count = 1;
- //word *arrWord = new word[count];
- ////iFB.open("BinDictionary.txt", ios::binary | ios::in);
- //if (iFB)
- // search(iFB, arrWord, count);
- }
- system("pause");
- return 0;
- }
- void reWrite(ifstream & iF, ofstream & oFB)
- {
- string output;
- word outWord;
- while (!iF.eof()) {
- iF >> output;
- outWord.key = stoi(output);
- iF >> output;
- outWord.engWord = output;
- iF >> output;
- outWord.rusWord = output;
- oFB.write((char *)&outWord, sizeof(outWord));
- }
- oFB.close();
- iF.close();
- }
- void readBin(ifstream & iFB)
- {
- if (!iFB.eof()) {
- word outWord;
- iFB.read((char *)&outWord, sizeof(outWord));
- while (!iFB.eof())
- {
- cout << outWord.key << endl;
- cout << outWord.engWord << endl;
- cout << outWord.rusWord << endl;
- iFB.read((char *)&outWord, sizeof(outWord));
- }
- iFB.close();
- }
- }
- void search(ifstream & iFB, word *arrWord, int &count)
- {
- string output;
- word outWord;
- iFB.read((char *)&arrWord[count-1], sizeof(outWord));
- while (!iFB.eof()) {
- word *arr2 = new word[++count];
- word *ar;
- ar = arrWord;
- for (int i = 0; i < count; i++)
- arr2 = ar;
- arrWord = arr2;
- delete[] ar;
- iFB.read((char *)&arrWord[count - 1], sizeof(outWord));
- }
- cout << "\n\tВывожу массив!" << endl;
- for (int i = 0; i < count; i++)
- cout << "arr[" << i << "] = " << arrWord->engWord << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement