title: How to read in data from a pgm file in C++
body: <p>So far I can read every line and print it out to the console:</p>
  
  <pre><code>void readFile(){
  
     string line;
     ifstream myfile("example1.pgm");
  
     if (myfile.is_open()){
         while (myfile.good()){
           getline (myfile,line);
           cout &lt;&lt; line;
         }
     }
  </code></pre>
  
  <p>However a pgm file apparently will always have the following at the start before the data:</p>
  
  <pre><code>P2
  # test.pgm
  24 7
  15
  </code></pre>
  
  <p>How can i adapt my code so that it checks that "P2" is present, ignores any comments (#), and stores the variables and subsequent pixel data? </p>
  
  <p>I'm a bit lost and new to c++ so any help is appreicated.</p>
  
  <p>Thanks</p>