title: non-blocking std::getline, exit if no input
body: <p>Currently I have a program that reads from the standard input, occasionally the program needs to just keep running if no input is made, usually this is a test script there is no 'enter' so to speak.</p>
  
  <p><code>program -v1 -v2 -v3 &lt;input &gt;output</code></p>
  
  <p>v1 - v3 are command line arguments respectively</p>
  
  <p>Basically the program spits out the command line arguments and their respective meaning to the program if no 'input' is given and then should exit.</p>
  
  <p>However at the moment if give it an empty test file or just run without pressing enter after running it blocks on the std::getline I use to input the commands.</p>
  
  <pre><code>while(std::getline(std::cin,foo)
  {do stuff}
  </code></pre>
  
  <p>where foo is a string. </p>
  
  <p>How do I get it to just run through and <code>do stuff</code> at least once then exit in the event of no input? In the event of input the <code>do stuff</code> occurs once for every line in standard input.</p>
  
  <p>Would a switch to a do-while loop, with a check pre loop as to whether it's got any input, work?</p>
  
  <p>Something like</p>
  
  <pre><code>if cin empty
  set flag
  
  do
   {do stuff
   check flag}
  while(getline)
  </code></pre>
  
  <p>or is non-blocking io not possible in c++?</p>
  
  <p>This question seems to be rehashed over and over but I couldn't find a definitive answer or even an answer that was platform agnostic(this program is academic in nature, coded on windows and tested on unix).</p>