When I make array of 550 (or more) objects (which contain ofstreams), first 509 objects are 'good' ones (with files etc.), but further objects are 'wrong'.
Have no clue what I made wrong.
Maybe special initialization of ofstream is needed?
This issue is for both 'Debug' and 'Release' versions.
Code (C++) (compiled under Microsoft Visual C++ 2012):
#include <iostream>
#include <fstream>
using namespace std;
class C {
int n;
ofstream f;
public:
C() {n=1;}
void Bind(char* filename);
};
void C::Bind(char* filename) {
f.open(filename,ios::binary);
if (!f) cout << "file " << filename << " Error..." << endl;
}
int main() {
C *c = new C[550];
for (int i=0;i<550;i++) {
char filename[256];
sprintf_s(filename, "file-%03d.bin", i);
c[i].Bind(filename);
}
return 0;
}
Output is:
file file-509.bin Error...
file file-510.bin Error...
file file-511.bin Error...
file file-512.bin Error...
file file-513.bin Error...
... ... ...
What's the magic of these 509 files?
How should I correct this code for array with 550 (or more) objects?
Thank you!