title: Proper Syntax for catching C++ input mismatch (String instead of int)
body: <p>What would be the proper syntax of catching input mismatch in this situation:</p>
  
  <pre><code>void getMonthlyBudget(fstream&amp; budgetFile, int months)
  {
      MonthlyBudget mb;
      int count = 1;
  
      budgetFile.open("budget.bin", ios::out|ios::binary);
      if(budgetFile.fail())
      {
        cout&lt;&lt;"Could not find file: budget.bin \n";
        system("PAUSE"); 
      }
  
      try
      {
          do
          {
              cout&lt;&lt;"Enter your housing budget for month "&lt;&lt;count&lt;&lt;":\n";
              cin&gt;&gt;mb.housing;
              cout&lt;&lt;"Enter your utilities budget for month "&lt;&lt;count&lt;&lt;":\n";
              cin&gt;&gt;mb.utilites;
              cout&lt;&lt;"Enter your household expense budget for month "&lt;&lt;count&lt;&lt;":\n";
              cin&gt;&gt;mb.houseHold;
              cout&lt;&lt;"Enter your transportation budget for month "&lt;&lt;count&lt;&lt;":\n";
              cin&gt;&gt;mb.transportation;
              cout&lt;&lt;"Enter your food budget for month "&lt;&lt;count&lt;&lt;":\n";
              cin&gt;&gt;mb.food;
              cout&lt;&lt;"Enter your medical budget for month "&lt;&lt;count&lt;&lt;":\n";
              cin&gt;&gt;mb.medical;
              cout&lt;&lt;"Enter your insurance budget for month "&lt;&lt;count&lt;&lt;":\n";
              cin&gt;&gt;mb.insurance;
              cout&lt;&lt;"Enter your entertainment budget for month "&lt;&lt;count&lt;&lt;":\n";
              cin&gt;&gt;mb.entertainment;
              cout&lt;&lt;"Enter your clothing budget for month "&lt;&lt;count&lt;&lt;":\n";
              cin&gt;&gt;mb.clothinng;
              cout&lt;&lt;"Enter your Miscellaneous budget for month "&lt;&lt;count&lt;&lt;":\n";
              cin&gt;&gt;mb.misc;
  
              budgetFile.write(reinterpret_cast&lt;char*&gt;(&amp;mb),sizeof(mb));
              count++;
              months --;
          }while(months != 0);
      }
  
      catch(...)
      {
          cin.clear(); 
          cin.ignore(numeric_limits&lt;streamsize&gt;::max(), '\n');
  
          cout&lt;&lt;"Error, invalid input entered.";
      }
  </code></pre>
  
  <p>The following output when the program catches input mismatch can be viewed <a href="https://i.stack.imgur.com/Gt0fO.png" rel="nofollow noreferrer">here</a>. I'm assuming the enter key is being picked up in this situation. </p>