title: Why the result differs when I press enter at the end of a sentence?
body: <p>Here is my first program</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main()
  {
      int a;
      string s;
      double d;
      while(cin &gt;&gt; a &gt;&gt; s &gt;&gt; d)
          cout &lt;&lt; a &lt;&lt; s &lt;&lt; d;
      return 0;
  }
  </code></pre>
  
  <p>When I input some simple data and press <kbd>Enter </kbd>, the result is shown immediately:</p>
  
  <p><a href="https://i.stack.imgur.com/DxQTC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DxQTC.png" alt="image"></a></p>
  
  <p>However, the code in another program behaves differently:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  struct Sales_data {
      string bookNo;
      unsigned units_sold = 0;
      double price = 0.0;
      void Print();
  };
  
  void Sales_data::Print(){//print every record of the Sales_data
      cout &lt;&lt; "The bookNo of the book is " &lt;&lt; bookNo &lt;&lt; endl;
      cout &lt;&lt; "The units_sold of the book is " &lt;&lt; units_sold &lt;&lt; endl;
      cout &lt;&lt; "The price of the book is " &lt;&lt; price &lt;&lt; endl;
  }
  
  int main()
  {
      Sales_data book;
      while(cin &gt;&gt; book.bookNo &gt;&gt; book.units_sold &gt;&gt; book.price);
          book.Print();
      return 0;
  }
  </code></pre>
  
  <p>When I run this code, input some data, and press <kbd>Enter</kbd>, it waits for me to input more data rather than show the result.</p>
  
  <p><a href="https://i.stack.imgur.com/UGxXW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UGxXW.png" alt="image"></a></p>
  
  <p>Could you explain this to me?</p>