title: Get input from terminal during runtime of a C++ program
body: <p>In GNOME terminal and XTerm in Ubuntu, I'm facing this problem:
  I am forced to input values for all  <code>cin</code> statements, irrespective of where they appear in source code, and only at the end executes all the <code>cout</code> statements. For instance:</p>
  
  <pre><code>int main()
  {
      int a;
      cout&lt;&lt;"Enter a :";
      cin&gt;&gt;a;
      cout&lt;&lt;"\n";
      return 0;
  }
  </code></pre>
  
  <p>When I run this code (using g++), I am forced to to input the value for <code>a</code> <em>before</em> the first <code>cout</code> statement runs.</p>
  
  <p><code>
  kanishk509@kanishk509-hp:~/Hackerearth$ g++ -Wall -o sample sample.cpp
  kanishk509@kanishk509-hp:~/Hackerearth$ ./sample
  5
  Enter a :
  </code></p>
  
  <p><a href="https://i.stack.imgur.com/nUioR.png" rel="nofollow noreferrer">image</a></p>
  
  <p>The '5' is the input that I am forced to provide to the statement <code>cin&gt;&gt;a</code> before the any <code>cout</code> statement runs.</p>