title: Omit the newline character in reading file with c++
body: <p>I have this code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  int main()
  {
      std::ifstream path("test");
      std::string separator(" ");
      std::string line;
      while (getline(path, line, *separator.c_str())) {
          if (!line.empty() &amp;&amp; *line.c_str() != '\n') {
              std::cout &lt;&lt; line &lt;&lt; std::endl;
          }
  
          line.clear();
      }
  
      return 0;
  }
  </code></pre>
  
  <p>The file "test" is populated with numbers, separated by various number of spaces. I need to read only the numbers, one by one and omit spaces and newlines. This code omits the blank spaces but not the newline character.</p>
  
  <p>These are few lines from the input file "test":</p>
  
  <pre><code>     3        19        68        29        29        54        83        53
      14        53       134       124        66        61       133        49
      96       188       243       133        46       -81      -156       -85
  </code></pre>
  
  <p>I think the problem is that this <code>*line.c_str() != '\n'</code> is not the proper way to determine if the string <code>line</code> hit newline character and the program keeps printing the newlines!</p>
  
  <p>This one works great:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  int main()
  {
      std::ifstream path("test");
      std::string separator(" ");
      std::string line;
      while (getline(path, line, *separator.c_str())) {
          std::string number;
          path &gt;&gt; number;
          std::cout &lt;&lt; number &lt;&lt; std::endl;
      }
  
      return 0;
  }
  </code></pre>