title: detecting white space characters, \t, \n, etc
body: <p>I am working through c++ primer 5th edition. the exercise in chapter 5 states the follow:</p>
  
  <blockquote>
    <p>Exercise 5.11: Write a program that counts the number of blank spaces, tabs, and newlines read.</p>
  </blockquote>
  
  <p>I attempted to do as exercise 5.11 did with the below code. However the code fails. Can anyone provide some examples of how i would correct the code so that when the input is read that the counter <code>unsigned int cnt = 0;</code> will be iterated correctly?  </p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  
  int main(){
      unsigned int cnt = 0;
      char c1;
      while (std::cin &gt;&gt; c1)
          if (c1 == '\t' || c1 == '\n' || c1 == ' ')
              ++cnt;
      std::cout &lt;&lt; "The number of spaces,tabs, newlines are: " &lt;&lt; cnt &lt;&lt; std::endl;
  
      system("pause");
      return 0;
  }
  </code></pre>