Не считываются данные из файла

Задача: Считать данные из файла, занести их в массив, провести действия с массивом, записать результат в выходной файл.

Использовал функцию ifstream.gcount() для подсчета количества символов. В выходной файл ничего не записывалось, но и сообщения об ошибке с открытием файла не возникало. Посмотрел под отладкой, обнаружил что SIZE остается со значением 0. В файле 9 значений, то есть ожидается что SIZE будет равняться 9. В чем здесь ошибка?

Содержимое папки:

введите сюда описание изображения

Текстовые файлы находятся в одной папке с main.cpp

input_data.txt:

1 2 3 4 5 6 7 8 9

main.cpp:

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {
    ifstream input_data;
    input_data.open("input_data.txt");

    if (!input_data.is_open()) {
        cout << "Error while opening file";
        system("pause");
        return 0;
    }

    int SIZE = input_data.gcount();

    double** arr = new double* [SIZE];
    for (int i = 0; i < SIZE; i++)
        arr[i] = new double[SIZE];
    
    for (int i = 0; i < SIZE; i++)
        for (int j = 0; j < SIZE; j++)
            input_data >> arr[i][j];
    

    double max;

    max = (arr[0][0] > arr[1][0]) ? arr[0][0] : arr[1][0];
    max = (arr[0][0] > arr[2][0]) ? arr[0][0] : arr[2][0];
    max = (arr[1][0] > arr[2][0]) ? arr[1][0] : arr[2][0];

    ofstream output_file;
    output_file.open("output_data.txt");

    if (!output_file.is_open()) {
        cout << "Error while opening file";
        system("pause");
        return 0;
    }
    else {
        for (int i = 0; i < SIZE; i++) {
            for (int j = 0; j < SIZE; j++) {
                output_file << setprecision(3) << fixed << arr[i][j] << " ";
            }
            output_file << endl;
        }
    }

    return 0;
}

Ответы (1 шт):

Автор решения: Lcashe
ifstream input_data;
    input_data.open("input_data.txt");

    if (!input_data.is_open()) {
        cout << "Error while opening file";
        system("pause");
        return 0;
    }


/*++++++++++++++++++++++++++++++++++++++++++++*/
    int count = 0;

    while (!input_data.eof()) {
        char ch;
        while (input_data >> ch)
            count++;
    }

    int SIZE = sqrt(count);
/*++++++++++++++++++++++++++++++++++++++++++++*/

    double** arr = new double* [SIZE];
→ Ссылка