Reading text from several files C++
<p>I have some text files in a folder named foo1, foo2,...,foo5. I tried to write a C++ program 
to print out the contents of the files but the compiler is giving an error. 
Here is the program.</p>

<pre><code>int main(int argc, char *argv[])
{

  string common="foo";

  for(int count=1;count&lt;=5;++count)
  {
  //Convert count to an string.
  stringstream ss;
  ss&lt;&lt;count;
  string numstring=ss.str();

  string filename=common+numstring;
  ifstream infile(filename); 
  string line;

  //Print out the lines from the file.
   while(getline(infile,line))
     {
       cout&lt;&lt;line&lt;&lt;endl;

     }
  }

  return 0;
}
</code></pre>

<p>The compiler is giving an error like</p>

<pre><code>g++ -Wall c++.cpp
c++.cpp: In function ‘int main(int, char**)’:
c++.cpp:26: error: no matching function for call to ‘std::basic_ifstream&lt;char, std::char_traits&lt;char&gt; &gt;::basic_ifstream(std::string&amp;)’
/usr/include/c++/4.4/fstream:454: note: candidates are: std::basic_ifstream&lt;_CharT, _Traits&gt;::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.4/fstream:440: note:                 std::basic_ifstream&lt;_CharT, _Traits&gt;::basic_ifstream() [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.4/iosfwd:81: note:                 std::basic_ifstream&lt;char, std::char_traits&lt;char&gt; &gt;::basic_ifstream(const std::basic_ifstream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)
</code></pre>

<p>Can someone help me out with this? The output of the program should be what I would get if I typed <code>cat foo*</code> at the terminal. </p>
