title: Why reading from a stream does not require a buffer flush
body: <p>Just started C++ learning by <strong><em>C++ Primer 5th ed.</em></strong></p>
  
  <p>The very first example of the book on page 6 is as followed</p>
  
  <pre><code>#include &lt;iostream&gt;
  int main()
  {
      std::cout &lt;&lt; "Enter two numbers:" &lt;&lt; std::endl; 
      int v1 = 0, v2 = 0; 
      std::cin &gt;&gt; v1 &gt;&gt; v2;
      std::cout &lt;&lt; "The sum of " &lt;&lt; v1 &lt;&lt; " and " &lt;&lt; v2
          &lt;&lt; " is " &lt;&lt; v1 + v2 &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>The manipulator <strong><em>endl</em></strong> insert newline and flush the buffer. </p>
  
  <p>soon followed by the code snipe in the page 7, the author emphasized that </p>
  
  <blockquote>
    <p>Programmers often add print statements during debugging. Such
    statements should always flush the stream. Otherwise, if the program
    crashes, output may be left in the buffer, leading to incorrect
    inference about where the program crashed</p>
  </blockquote>
  
  <p>From the code example and the emphasized warning I feel it is important to do the flush when writing to a Stream </p>
  
  <p><strong>Here is the part I don't understand</strong>, how a bout reading from a stream case, such as <strong>std::cin</strong>, is there any necessary to do the flush then?</p>
  
  <p><strong>Appended Question：</strong> </p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main()
  {
      int sum = 0, val = 1;
      while (val &lt;= 5) {
          sum += val;
          ++val;
          std::cout &lt;&lt; sum &lt;&lt; std::endl; //test
      }
  }
  </code></pre>
  
  <p>When I changed the line marked with <strong><em>test</em></strong> to <strong>std::cout &lt;&lt; sum &lt;&lt; '\n';</strong>, there is no visual difference in the console. Why is that, isn't it supposed to print as follows if there is no flush for each loop?</p>
  
  <pre><code>1
  1 3
  1 3 6 
  1 3 6 10
  1 3 6 10 15
  </code></pre>
  
  <p>Thanks </p>