I've got this issue with allocation of an array of some objects that I need to initialize with some constructor. Let me show what I mean:
ofstream* out = new ofstream[10];
for(int i = 0; i < 10; i++){
stringstream ss;
ss << "file" << i << ".txt";
string str(ss.str());
char *fileName = (char*)str.c_str();
out[i] = ofstream(fileName); //Now, this is wrong
}
And I need some help on the wrong marked line. How do I allocate each member of that array?
And thank you for not pointing me to other posts (I looked on a lot before posting)
outis susceptible to a memory leak. Remember to calldelete[]on out.