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


#include <iostream>
#include <fstream>
#include <clocale>

using namespace std;

int main()
{
    // Настройка русской локали
    setlocale(LC_ALL, "Russian");

    // Открытие файлов: in2.txt для чтения, out2.txt для записи
    fstream fin("in2.txt", ios::in);
    fstream fout("out2.txt", ios::out);

    // Проверка открытия файлов
    if (!fin.is_open() || !fout.is_open())
    {
        cout << "Ошибка: не удалось открыть файл in2.txt или out2.txt!" << endl;
        system("pause");
        return 1;
    }

    // Размеры матрицы Y по варианту 10: 7 строк, 6 столбцов
    const int rows = 7;
    const int cols = 6;
    int Y[rows][cols];

    // Считывание элементов матрицы из файла in2.txt
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < cols; j++)
        {
            fin >> Y[i][j];
        }
    }

    // Вывод сформированной матрицы на экран
    cout << "Сформированная матрица Y (7x6):" << endl;
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < cols; j++)
        {
            cout << Y[i][j] << " ";
        }
        cout << endl;
    }

    // Запись сформированной матрицы в файл out2.txt
    fout << "Сформированная матрица Y (7x6):" << endl;
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < cols; j++)
        {
            fout << Y[i][j] << " ";
        }
        fout << endl;
    }

    // Закрытие файлов
    fin.close();
    fout.close();

    system("pause");
    return 0;
}