title: Read new line character in fstream C++
body: <p>How do I read the new line character? I am trying to do a character count, but the new line gets in the way. I tried doing <code>if (text[i] == ' ' &amp;&amp; text[i] == '\n')</code> but that didn't work. <a href="https://repl.it/@chipsahui/SqueakyWhiteCrayfish" rel="nofollow noreferrer">Here is my repl.it session</a>.</p>
  
  <p>I am trying to read this from file.txt:</p>
  
  <pre><code>i like cats
  dogs are also cool
  so are orangutans
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  int main()
  {
      ifstream input;
      input.open("file.txt");
  
      int numOfWords = 0;
  
      while (true)
      {
          string text;
          getline(input, text);
  
          for(int i = 0; i &lt; text.length(); i++)
          {
              if (text[i] == ' ') 
              {
                  numOfWords++;
              }
          }
  
          if (input.fail())
          {
              break;
          }
      }
      cout &lt;&lt; "Number of words: " &lt;&lt; numOfWords+1 &lt;&lt; endl;
      input.close();
  }
  </code></pre>