Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <clocale>
  6.  
  7. using namespace std;
  8.  
  9. struct word {
  10. int key;
  11. string engWord;
  12. string rusWord;
  13. };
  14.  
  15. void reWrite(ifstream &iF, ofstream &oFB);
  16. void readBin(ifstream &iFB);
  17. void search(ifstream &iFB, word *arrWord, int &count);
  18.  
  19. int main()
  20. {
  21. setlocale(LC_ALL, "RUS");
  22.  
  23. ifstream iF("Dictionary.txt", ios::in);
  24. ofstream oFB("BinDictionary.txt", ios::binary|ios::out);
  25.  
  26. if (iF && oFB)
  27. {
  28. reWrite(iF, oFB);
  29.  
  30. ifstream iFB("BinDictionary.txt", ios::binary | ios::in);
  31. if (iFB)
  32. readBin(iFB);
  33. //
  34. //int count = 1;
  35. //word *arrWord = new word[count];
  36. ////iFB.open("BinDictionary.txt", ios::binary | ios::in);
  37. //if (iFB)
  38. // search(iFB, arrWord, count);
  39. }
  40.  
  41.  
  42. system("pause");
  43. return 0;
  44. }
  45.  
  46. void reWrite(ifstream & iF, ofstream & oFB)
  47. {
  48. string output;
  49. word outWord;
  50.  
  51. while (!iF.eof()) {
  52. iF >> output;
  53. outWord.key = stoi(output);
  54. iF >> output;
  55. outWord.engWord = output;
  56. iF >> output;
  57. outWord.rusWord = output;
  58. oFB.write((char *)&outWord, sizeof(outWord));
  59. }
  60. oFB.close();
  61. iF.close();
  62. }
  63.  
  64. void readBin(ifstream & iFB)
  65. {
  66. if (!iFB.eof()) {
  67. word outWord;
  68.  
  69. iFB.read((char *)&outWord, sizeof(outWord));
  70. while (!iFB.eof())
  71. {
  72. cout << outWord.key << endl;
  73. cout << outWord.engWord << endl;
  74. cout << outWord.rusWord << endl;
  75.  
  76. iFB.read((char *)&outWord, sizeof(outWord));
  77. }
  78. iFB.close();
  79. }
  80.  
  81. }
  82.  
  83. void search(ifstream & iFB, word *arrWord, int &count)
  84. {
  85. string output;
  86. word outWord;
  87.  
  88. iFB.read((char *)&arrWord[count-1], sizeof(outWord));
  89.  
  90. while (!iFB.eof()) {
  91. word *arr2 = new word[++count];
  92. word *ar;
  93. ar = arrWord;
  94. for (int i = 0; i < count; i++)
  95. arr2 = ar;
  96. arrWord = arr2;
  97. delete[] ar;
  98.  
  99. iFB.read((char *)&arrWord[count - 1], sizeof(outWord));
  100.  
  101. }
  102.  
  103. cout << "\n\tВывожу массив!" << endl;
  104. for (int i = 0; i < count; i++)
  105. cout << "arr[" << i << "] = " << arrWord->engWord << endl;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement