I am trying to write in multiple files using ofstream. The problem is that I'm not able to write to more than 1020 files at the same time. I don't understand if it's my laptop problem or if it's an internal limit of fstream.
I wrote a simplified version of my program. Obviously in this example it's not necessary to open multiple fstream channels.
#include <fstream>
#include <vector>
using namespace std;
int main(){
vector<ofstream> write(2000);
char namefile[50];
for(int i=0; i<2000; i++){
sprintf(namefile,"text_%d.txt",i);
write[i].open(namefile, ofstream::out);
if (write[i].fail())
printf("Error writing to %s\n", namefile);
write[i] << "Hello!";
write[i].flush();
}
for(int i=0; i<2000; i++)
write[i].close();
return 0;
}