# Reading a txt file: incompatible length error

**URL:** <https://community.freefem.org/t/reading-a-txt-file-incompatible-length-error/1244>\
**Category:** General Discussion\
**Created:** [October 4, 2021, 1:54pm UTC](https://community.freefem.org/t/reading-a-txt-file-incompatible-length-error/1244 "2021-10-04T13:54:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![distractor](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@distractor](https://community.freefem.org/u/distractor)\
**Post date:** [October 4, 2021, 1:54pm UTC](https://community.freefem.org/t/reading-a-txt-file-incompatible-length-error/1244/1 "2021-10-04T13:54:03Z")

</div>

Hi,

Attached is my txt file ([wetransfer link](https://we.tl/t-YBxJNjZPUb)).

I want to read the lines from the txt into a variable:

```auto
string filePath = "../data/";
string fileName = "Heat_frame_0.txt";

// Read file.
{
    ifstream file(filePath + fileName);
    real[int] Ttt(2838);
    file >> Ttt;
}

```

Yet this results in an error saying:

```bash
 length on the array 2838 != 0 length in file
  current line = 12
Exec error : Fatal Error: incompatible length in read array (Op_ReadKN)

```

But both array and file length are the same. I don’t get it.

---

<div class="post-metadata">

**Author:** ![distractor](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@distractor](https://community.freefem.org/u/distractor)\
**Post date:** [October 5, 2021, 8:48am UTC](https://community.freefem.org/t/reading-a-txt-file-incompatible-length-error/1244/2 "2021-10-05T08:48:16Z")

</div>

I found out that using the `getline` works way better.

```auto
      // Read file.
      {
          ifstream file(filePath + fileName);
          string line;
          // Read by line.
          for (int k = 0; k < Th.nv; k++){
            getline(file, line);
            temperatureField(k) = atof(line);
          }
      }

```
