Загрузка данных


#include <iostream>
#include <fstream>
#include <string>

// 3

int main() {
    setlocale(LC_ALL, "RUS");

    std::ifstream file1("file1.txt");
    std::ifstream file2("file2.txt");

    if (!file1.is_open()) {
        std::cerr << "Не удалось открыть file1.txt\n";
        return 1;
    }
    if (!file2.is_open()) {
        std::cerr << "Не удалось открыть file2.txt\n";
        return 1;
    }


    std::ofstream out("out.txt");
    if (!out.is_open()) {
        std::cerr << "Не удалось создать out.txt\n";
        return 1;
    }

    std::string line1, line2;
    int lineNum = 0;
    bool filesAreEqual = true;
    int firstDiffLine = -1;


    while (true) {
        bool got1 = (bool)std::getline(file1, line1);
        bool got2 = (bool)std::getline(file2, line2);

        if (!got1 && !got2) break;

        lineNum++;

        if (got1 != got2 || line1 != line2) {
            filesAreEqual = false;
            firstDiffLine = lineNum;
            break;
        }
    }


    std::string result;
    if (filesAreEqual) {
        result = "Все строки совпадают.";
    }
    else {
        result = "Первое отличие в строке: "
            + std::to_string(firstDiffLine);
    }

    std::cout << result << "\n";
    out << result << "\n";

    file1.close();
    file2.close();
    out.close();

    return 0;
}