title: Loading Data From Comma Separated Text File to 2D Array?
body: <p>I am trying to load data from a text file that looks like this:</p>
  
  <p>161,77,88,255
  0,44,33,11,111</p>
  
  <p>etc. I have functions to manipulate it, and am ensured that the array is the correct size (which may still vary). Below is my attempt at implementation:</p>
  
  <pre><code>bool loadData(int **imgPix, string fileName) {
  
  ifstream inputFile;
  
  inputFile.open(fileName.c_str());
  
  string tempLineRow; //The resulting line from the text file
  string tempElementColumn; //The individual integer element 
  int numberOfCols = 0;
  int numberOfRows = 0;
  
  
  if (!inputFile.is_open()) {
      return false;
  }
  
  imgPix = new int* [numberOfRows];
  
      while (getline(inputFile, tempLineRow, '\n')) {
  
          stringstream ss; 
          ss &lt;&lt; tempLineRow; //Stringstream version of the line
  
          while (getline(ss, tempElementColumn, ',' )) {
              stringstream ss2; 
              ss2 &lt;&lt; tempElementColumn;
              ss2 &gt;&gt; numberOfCols;
  
  //Prob?         (**imgPix) = *(*(imgPix + numberOfRows) + numberOfCols);
              numberOfCols++;
  
          }
  
          numberOfRows++;
  
      }   
  
  inputFile.close();
  return true;
  </code></pre>
  
  <p>}</p>
  
  <p>I've marked the line with the double pointer assignment with a comment, because I believe it be the source of my error, although there could be others. I'm not sure how to use the while loop structure I've implemented to iteratively update the 2D array.</p>
  
  <p>Can anyone offer any assistance? Would be greatly appreciated!</p>