#include <iostream>
    using namespace std;
    using std::cerr;
    using std::cout;
    using std::endl;
    #include <sstream>
 #include <string>

    #include <fstream>
    using std::ifstream;

    #include <cstdlib>

    int main()
       ifstream indata; // indata is like cin
       char num;
       int sar,ri,sat,ha;
       char s[]=".txt";
       for(int some_int=1;some_int<=3;some_int++){
       ostringstream buffer;
       buffer <<some_int;
       string s1 =buffer.str();

      if(!indata) { // file couldn't be opened
      cerr << "Error: file could not be opened" << endl;
 // opens the file
      indata >> num;
       while ( !indata.eof() ) { // keep reading until end-of-file
                      case 'a':sar+=1;break;
                      case 'b':ri+=1;break;
                      case 'c':sat+=1;break;
                      case 'd':ha+=1;break;}
                      indata >> num;
       cout<<"saransh :"<<sar<<"\n"<<"rishul :"<<ri<<"\n"<<"satpal :"<<sat<<"\n"<<"Harsh :"<<ha;
       cout << "\nEnd-of-file reached.." << endl;
       return 0;

i have 3 files in my src folder named as(1.txt,2.txt and 3.txt) but after using for loop its giving error means its not opening any file......plz help what changes to do so that i can accees these files and their content one by one.

line 51: close() does not clear the end-of-file flag. After calling close() call clear() so that indata can be used for subsequent loop iterations. Another way to do it is to move line 18 down so that its inside the loop (line 25).

i am not getting you sir, can you write it plzzz