title: reading a file of unknown length with a function
body: <p>I'm trying to write a short function that will let me quickly read in a file of unknown size and return pointer to the array of data and the length of that array but it seems my code isn't working. What am i doing wrong?</p>
  
  <pre><code>int readIn(int* pointer, param parameters, string description)
  {
      string fileName = parameters.fileName + " " + description + ".bin";
  
      ifstream readFile;
      readFile.open(fileName.c_str(), ios::in|ios::binary|ios::ate);  
  
      int size = readFile.tellg();
      int length = size / 4;
      int* output = new int [length];
  
      readFile.seekg (0, ios::beg);
      readFile.read(reinterpret_cast&lt;char*&gt;(output), (size));
      readFile.close();
  
      pointer = output; // link new array with the pointer
      return length;
  }
  </code></pre>
  
  <p>and in the main function:</p>
  
  <pre><code>int* testList;
  int numEntries = readIn(testList, parameters, "test");
  </code></pre>
  
  <p>I end up with an error saying that my testList variable was used and not initialized. What am i doing wrong?</p>