title: clear() goes into infinite loop
body: <p>The output is an infinite loop of "cannot open the file". what did I do wrong? thanks in advance. (p.s I am trying to test the condition that it cannot open the file and continue processing by getting the next file name from the vector)</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;istream&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  using namespace std;
  int main ()
  {
  ifstream input;
  vector&lt;string&gt; files;
  files.push_back("ifile");
  files.push_back("ifile2");
  vector&lt;string&gt;::const_iterator iter=files.begin();
  while (iter!=files.end())
  {   
      string s;
      input.open(iter-&gt;c_str());
      if (!input)
      {
          cerr&lt;&lt;"cannot open the file"&lt;&lt;endl;
          input.close();
          input.clear();
          continue;
      }
      while(input&gt;&gt;s)
          cout&lt;&lt;s&lt;&lt;' '&lt;&lt;ends;
      input.close();
      input.clear();
      cout&lt;&lt;endl;
      ++iter;
  }
  return 0;
  }
  </code></pre>