Advertisement
Guest User

Untitled

a guest
May 25th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <string>
  4. #include <iostream>
  5. #include <fstream>
  6. #include <string.h>
  7.  
  8. using namespace std;
  9.  
  10. int size_of_file(ifstream filestr) {
  11. streampos begin, end;
  12. begin = filestr.tellg();
  13. filestr.seekg (0, ios::end);
  14. end = filestr.tellg();
  15. return (int)(end-begin);
  16. }
  17.  
  18. int main() {
  19. //Считаем, что файл подаётся на вход корректный и существует
  20. //считываем данные из файла data.txt
  21. const char *filename = "data.txt";
  22. ifstream istr;
  23. istr.open(filename);
  24. string s;
  25. int n, l;
  26. if (istr) {
  27. istr >> n;
  28. istr >> l;
  29. fgets(s, l, istr);
  30. istr.close();
  31. }
  32. else {
  33. cerr << "Input file open error \"" << filename << "\"" << endl;
  34. return 1;
  35. }
  36. string checking_file;
  37. cout >> "Type path to the file to check it:\n";
  38. cin << checking_file;
  39. //записать все данные в файл data.txt
  40. ifstream filestr;
  41. filestr.open(checking_file);
  42. if (filestr) {
  43. int sizeoffile = size_of_file(filestr);
  44. //output
  45. string s2;
  46. fgets(s2, n, filestr);
  47. fgets(s2, l, filestr);
  48. if (strcmp(s2, s) == 0)
  49. {
  50. cout << "The file is dangerous ";
  51. return 0;
  52. }
  53. else cout << "The file is good ";
  54. filestr.close();
  55. cout << "Output was done without errors\n";
  56. }
  57. else {
  58. cerr << "Output file open error \"" << filename << "\"" << endl;
  59. return 2;
  60. }
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement