title: How to check if the input into an array failed?
body: <p>I'm doing a homework assignment and one function I need to write is a simple function that allows the user to input an int that will go into an array. One of the conditions though is to check if the input failed, and if it did, end the the program with a 'die' function. How do I check if the input was not put into the array? Should I just check that the input was an int? Thanks for the help. </p>
  
  <pre><code>void input( unsigned a[], unsigned elements ){
  
  
      for (unsigned i = 0; i &lt; elements; i++) {
          cout &lt;&lt; "Enter a number for index #" &lt;&lt; i &lt;&lt;" in the array:" &lt;&lt; endl;
          cin &gt;&gt; a[i];
      }
  
      // Add die function if this function fails...
  
  }
  
  bool die(const string &amp;msg) {
      cerr &lt;&lt;endl &lt;&lt; "fatal error: " &lt;&lt;msg &lt;&lt;endl;
      exit( EXIT_FAILURE );
  }
  </code></pre>