0

Is there a faster way of reading a text file 768 lines long and 1024 wide than the solution I have here?

double* FileIO::readTXT(int rows, int cols, char* fileName)
{
    double* data = new double[rows * cols];
    auto i = 0, total = (cols * rows) - 1;
    ifstream clutteredTXT(fileName);
    if (clutteredTXT.is_open())
    {
        while (clutteredTXT.good())
        {
            if (i > total)
            {
                break;
            }
            clutteredTXT >> *(data + i);
            i++;
        }
        clutteredTXT.close();
    }
    else
    {
        cout << "Unable to open file" << fileName << endl;
    }
    return data;
}
loxol
  • 83
  • 7

0 Answers0