title: Proper use of EOF (can it be used multiple times in a program?)
body: <p>In my intro to programming course (c++), the instructor told us to:</p>
  
  <blockquote>
    <p>"Write a program that inputs an unspecified number of integer ("int")
    values and then outputs the minimum value and the maximum value that
    were entered. At least one value will always be input. (read all input
    until EOF). For extra credit make your program also work when the user
    doesn't enter any ints at all (just the EOF.)"</p>
  </blockquote>
  
  <p>I wanted to get fancy, so, in my solution, when just <code>EOF</code> is entered, the program responds with <code>"Oops! You didn't enter anything. Please try again, this time entering at least one integer: "</code> and prompts for input again.</p>
  
  <p>My instructor is saying that this answer is wrong because </p>
  
  <blockquote>
    <p>After the EOF, there should be no more input to a program (neither
    expected by the user nor the program) — using the <code>EOF</code> to switch from
    “one mode” of input to another mode of input isn’t supporting the
    standards.</p>
  </blockquote>
  
  <ol>
  <li>Every definition of <code>EOF</code> I've found on the internet doesn't seem to support my professor's definition. <code>EOF</code>, from what I can tell, is simply defined as the end of the current file. It seems perfectly valid to accept input from a user until <code>EOF</code>, do something with that input, and then ask for additional input until <code>EOF</code> again.</li>
  <li>Because this is an online course, I was able to review everything we learned relating to <code>EOF</code> and we were only told that <code>EOF</code> meant "End of File" and could be 'used to signal an end to user input' (important, because, even if my professor was wrong, one could argue that I should have adopted his standards if he had specifically told us to. But he didn't tell us to).</li>
  </ol>
  
  <p><strong>What is the proper way to use <code>EOF</code> with user input? Is my professor's statement that "After the EOF, there should be no more input to a program" the standard
   and expected way to use EOF? If a program accepts a variable amount of input, does something with it, and then accepts more variable input, is it not acceptable to use <code>EOF</code> with those inputs (aka don't use <code>while(cin &gt;&gt; user_input)</code> in that scenerio)? If so, is there a standard for what should be used to signal end of input in a scenario where you're accepting variable input multiple times?</strong></p>
  
  <p>My exact solution to the assignment is below. My solution to the main assignment "Write a program that inputs an unspecified number of integer ("int") values and then outputs the minimum value and the maximum value that were entered" was considered correct, by the second part of the assignment "make your program also work when the user doesn't enter any ints at all (just the EOF.)" was deemed incorrect ("make the program also work" is the only prompt we were given).</p>
  
  <p>Thanks so much for any feedback!! Obviously, I'm skeptical of my professors feedback / decision, but, in general, I'm just trying to get a sense of C++ community standards.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  #include &lt;stdlib.h&gt;
  
  using namespace std;
  
  int main(){
    string user_input;
  
    int int_input, min_user_input, max_user_input;
    bool do_it = true;
  
    cout &lt;&lt; "Hi John," &lt;&lt; endl;
    cout &lt;&lt; "Please enter a few integers (signal EOF when finished): ";
  
    while(do_it) {
      cin.clear();
      cin &gt;&gt; user_input;
  
      if (user_input.empty()) {
        cout &lt;&lt; endl;
        cout &lt;&lt; "Oops! You didn't enter anything. Please try again, this time entering at least one integer: ";
      }
      else {
        try {
          int_input = atoi( user_input.c_str() );
  
          min_user_input = int_input;
          max_user_input = int_input;
  
          while(cin &gt;&gt; int_input) {
            if (min_user_input &gt; int_input) {
              min_user_input = int_input;
            }
  
            if (max_user_input &lt; int_input) {
              max_user_input = int_input;
            }
          }
  
          cout &lt;&lt; endl;
          cout &lt;&lt; "The max user input was: " &lt;&lt; max_user_input &lt;&lt; endl;
          cout &lt;&lt; "The min user input was: " &lt;&lt; min_user_input &lt;&lt; endl;
          do_it = false;
        }
        catch (std::invalid_argument) {
          cout &lt;&lt; endl;
          cout &lt;&lt; "Oops! You didn't enter an integer. Please try again, this time only entering integers: ";
          do_it = true;
        }
      }
    }
  
    return 0;
  }
  </code></pre>
  
  <p><em>Note: additional feedback I got on this submission was: to not use c libraries (apparently <code>stdlib.h</code> is one) and that, on some computers (though, apparently, not mine), <code>#include &lt;stdexcept&gt;</code> will be needed to compile.</em></p>
  
  <h1>Answer</h1>
  
  <p>Short answer: my instructor is correct. When used with <code>cin</code>, no additional user input should follow an <code>EOF</code> signal. Apparently, in some cases the program won't let you enter more information, but, as @hvd points out</p>
  
  <blockquote>
    <p>Although your system may let you continue reading from the same file
    in the specific case that it is coming from a TTY, due to EOF being
    faked there, you shouldn't generally rely on that.</p>
  </blockquote>
  
  <p>Aka, because I'm using a terminal to enter user input, the program happens to work. In general, it won't work though.</p>
  
  <p>As @RSahu answers, EOF just shouldn't be used to signal the end of variable length <code>cin</code> multiple times in a program. Importantly</p>
  
  <blockquote>
    <p>There is no standard means, or commonly practiced coding standard, of
    indicating when user input has ended for the time being. You'll have
    to come up with your own mechanism. For example, if the user enters
    "end", you can use it to deduce that the user has ended input for the
    time being. However, you have to indicate to the user that that's what
    they need to enter. Of course, you have to write code to deal with
    such input.</p>
  </blockquote>
  
  <p>Because this assignment required the use of EOF, what I was attempting to accomplish was, unintentionally, prohibited (aka receive input, check it, possibly receive more input).</p>