std::string file=random(1);
std::ofstream o(file);
should be:
std::string file=random(1);
std::ofstream o(file.c_str());
since ofstream
's constructor expects const char*
.
Also consider using the following function instead of rand() % 62
:
inline int irand(int min, int max) {
return ((double)rand() / ((double)RAND_MAX + 1.0)) * (max - min + 1) + min;
}
...
srand(time(NULL)); // <-- be careful not to call srand in loop
std::string r;
r.reserve(len); // <-- prevents exhaustive reallocation
for (int i = 0; i < len; i++)
r.push_back( a[irand(0,62)] );