Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <string>
  4. #include <Windows.h>
  5. using namespace std;
  6.  
  7. void merge(ifstream &f1, ifstream &f2, ofstream &fRes)
  8. {
  9. string one[3], two[3];
  10. while (!f1.eof() && !f2.eof())
  11. {
  12. getline(f1, one[0], ':');
  13. getline(f1, one[1], ':');
  14. getline(f1, one[2]);
  15. getline(f2, two[0], ':');
  16. getline(f2, two[1], ':');
  17. getline(f2, two[2]);
  18. if (one[1] == two[0] && one[2] == two[1])
  19. fRes << one[0] << ':' << two[2] << endl;
  20. }
  21. }
  22.  
  23. int main()
  24. {
  25. string file1path, file2path, fileResultPath;
  26. ifstream file1, file2;
  27. ofstream fileResult;
  28.  
  29. SetConsoleCP(1251);
  30. SetConsoleOutputCP(1251);
  31.  
  32. cout << "Путь к первому файлу > ";
  33. getline(cin, file1path);
  34. cout << "Путь ко второму файлу > ";
  35. getline(cin, file2path);
  36. cout << "Путь к файлу для записи результата > ";
  37. getline(cin, fileResultPath);
  38.  
  39. file1.open(file1path);
  40. file2.open(file2path);
  41. fileResult.open(fileResultPath);
  42.  
  43. if (file1.is_open() && file2.is_open())
  44. {
  45. merge(file1, file2, fileResult);
  46. cout << "Готово!\n";
  47. }
  48. else
  49. cout << "Проблема с открытием файлов!\n";
  50.  
  51. file1.close();
  52. file2.close();
  53. fileResult.close();
  54.  
  55. system("pause");
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement