プロジェクトでテキストを書き込むために 41 個の出力ファイルを使用したいと考えています。最初にこれらの出力ファイルに名前を付ける文字列配列list
を作成してから、ストリームオブジェクトの配列を定義して名前を付けようとしましlist
たが、このエラーが発生し'outfile' cannot be used as a function
ます. 以下は私のコードです:
#include <sstream>
#include <string>
#include <iostream>
#include <fstream>
using namespace std ;
int main ()
{
string list [41];
int i=1;
ofstream *outFile = new ofstream [41];
for (i=1;i<=41 ;i++)
{
stringstream sstm;
sstm << "subnode" << i;
list[i] = sstm.str();
}
for (i=0;i<=41;i++)
outFile[i] (list[i].c_str());
i=1;
for (i=1;i<=41;i++)
cout << list[i] << endl;
return 0;
}