title: Reading a file into character array in C++
body: <p>I have been writing code to read a file into character array using C++. I have tried to skip over white space characters but I am getting space and newline in my output array.</p>
  
  <p>This is a function within the class with <em>label</em> declared as character array.</p>
  
  <pre><code>        //Read the label file
   80     this-&gt;label = new char[vert_count+1];
   81     std::ifstream file1;
   82     file1.open(label_file);
   83     if(file1 != NULL)
   84     {
   85         char temp; int i = 0;
   86         std::cout &lt;&lt; "Label file opened successfully" &lt;&lt; std::endl;
   87         if( i&lt; vert_count)
   88         {
   89             file1.get(temp);
   90             if(temp != ' ' &amp;&amp;  temp != '\n'&amp;&amp; temp != '\t')
   91             {
   92                 label[i] = temp;
   93                 i++; 
   94             }
   95         }
   96         label[vert_count] = '\0';//putting null character to terminate
   97         file1.close(); 
   98     }
   99     else        
  100         std::cout &lt;&lt; "label file cannot be opened\n";
  101     for (int i = 0; i&lt; vert_count; i++)
  102         std::cout &lt;&lt;label[i];
  </code></pre>
  
  <p>my input file is of format as shown below</p>
  
  <pre><code>a
  b
  c
  d
  e
  f
  1
  2
  H
  M
  O
  </code></pre>
  
  <p>The output I am getting is bunch of characters at start and then white space and new line only.</p>