我有这个问题,需要用一些构造函数初始化一些对象的数组。让我告诉我的意思:C++ alloc对象数组
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
}
我需要在wrong
标记线一些帮助。我该如何分配数组的每个成员?
谢谢你不指着我的其他职位(我看到了很多发布前)
放置新的'out'是容易发生内存泄漏。记得调用'delete []'打开。 – 2011-04-12 20:05:41
做到了,谢谢:) – 2011-04-12 20:50:59