Skip non-integers from text file C++
<p>I have a program which reads integers from a text file and skips non-integers and strange symbols. Then text file looks like:</p>

<pre><code># Matrix A   // this line should be skipped because it contains # symbol
1 1 2
1 1$ 2.1      // this line should be skipped because it contains 2.1 and $
3 4 5
</code></pre>

<p>I have to print out the matrix without strange symbols and non-integers line. That is the output should be:</p>

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

<p>My code</p>

<pre><code>ifstream matrixAFile("a.txt", ios::in); // open file a.txt
if (!matrixAFile)
{
      cerr &lt;&lt; "Error: File could not be opened !!!" &lt;&lt; endl;
      exit(1);
}

int i, j, k;
while (matrixAFile &gt;&gt; i &gt;&gt; j &gt;&gt; k)
{
      cout &lt;&lt; i &lt;&lt; ' ' &lt;&lt; j &lt;&lt; ' ' &lt;&lt; k;
      cout &lt;&lt; endl;
}
</code></pre>

<p>But it fails when it gets the first # symbol. Anyone helps please ?</p>
