title: How to Determine if STDIN is Empty?
body: <p>I'm writing an emulator for my Operating Systems course. The problem I have is that we need to get all our .job files (they are like application programs being fed to the emulator) from STDIN and read them in. </p>
  
  <p>Call:</p>
  
  <pre><code>./RMMIX &lt; aJob.job
  </code></pre>
  
  <p>I just slurp it with </p>
  
  <pre><code>while(getline(std::cin, line)) 
  </code></pre>
  
  <p>line by line. The problem is, if I do not put anything to STDIN, then cin will wait for user input- NOT what I want. I need the program to recognize a lack of text on STDIN and terminate, not wait for user input instead.</p>
  
  <p>I have determined that I can query the length like so:</p>
  
  <pre><code>size_t beg = std::cin.tellg();
  std::cin.seekg(0, std::ios_base::end);
  size_t end = std::cin.tellg();
  std::cin.seekg(0, std::ios_base::beg);
  </code></pre>
  
  <p>and terminate if std::cin has a length of 0.</p>
  
  <p>Are there any other solutions to this? Is this a portable solution?</p>