Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <string>
- #include <iostream>
- #include <fstream>
- #include <string.h>
- using namespace std;
- int size_of_file(ifstream filestr) {
- streampos begin, end;
- begin = filestr.tellg();
- filestr.seekg (0, ios::end);
- end = filestr.tellg();
- return (int)(end-begin);
- }
- int main() {
- //Считаем, что файл подаётся на вход корректный и существует
- //считываем данные из файла data.txt
- const char *filename = "data.txt";
- ifstream istr;
- istr.open(filename);
- string s;
- int n, l;
- if (istr) {
- istr >> n;
- istr >> l;
- fgets(s, l, istr);
- istr.close();
- }
- else {
- cerr << "Input file open error \"" << filename << "\"" << endl;
- return 1;
- }
- string checking_file;
- cout >> "Type path to the file to check it:\n";
- cin << checking_file;
- //записать все данные в файл data.txt
- ifstream filestr;
- filestr.open(checking_file);
- if (filestr) {
- int sizeoffile = size_of_file(filestr);
- //output
- string s2;
- fgets(s2, n, filestr);
- fgets(s2, l, filestr);
- if (strcmp(s2, s) == 0)
- {
- cout << "The file is dangerous ";
- return 0;
- }
- else cout << "The file is good ";
- filestr.close();
- cout << "Output was done without errors\n";
- }
- else {
- cerr << "Output file open error \"" << filename << "\"" << endl;
- return 2;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement