How to read in a matrix from a file in C++?
<p>I am attempting to read in an <i>n</i> &times; <i>n</i> matrix from a file and then store that matrix in a one dimensional array. I would also like to store the value for <i>n</i>. I have looked into various approaches but can't seem to apply them to what I'm trying to achieve.</p>

<p>This is what I have so far but I'm unsure what to put into the while loop.</p>

<pre><code>/*READ IN THE IMAGE MATRIX FROM THE FILE*/

String lineA;
ifstream imFile;
imFile.open("imageMatrixDefined.txt");
if(imFile.fail()){
    cerr &lt;&lt; "File cannot be found or opened" &lt;&lt; endl;
    exit(1);
}

if(imFile.is_open(){
    cout &lt;&lt; "file opened successfully!" &lt;&lt; endl;
    while(!imFile.eof()){    
    }
}
</code></pre>

<p>The input file could look like the following:</p>

<pre><code>1    2    3
2    3    1
3    3    2
</code></pre>

<p>where a tab separates the elements.
Any suggestions would be greatly appreciated as I'm new to C++.</p>