ok i need to make an array of outfile file streams that will make about 16 different files. the files need to be named like funcfile0, funcfile1, funcfile2, etc. all the way to funcfile15. the name of the 'funcfile' part will be a char array input from the user. so i set char funcfile[15]; and then cin >> funcfile.
so my question is creating an array of ofstream that will open the desired files. once i have created all 16 of the files, i need to write different data to each of the files. i currently have a for loop set up to change the file that it writes to and it will increment the file name after writing each file.
here is what my code looks like now and it will compile but when i run it, it will crash when its writing the first file.
Code:for(int ct=0;ct<16;ct++){ ofstream funcf[ct]; funcf[ct].open (funcfile+ct); if(funcf[ct].is_open()){ cout << "writing function file" << ct<< " ..."<<endl; int c1=0; funcf[ct] << setw(10)<<idim<<setw(10)<<jdim<<setw(10)<<kdim<<setw(10)<<"6"<<endl; for(int e3=0;e3<idim;e3++){ for(int e2=0;e2<jdim;e2++){ for(int e1=0;e1<kdim;e1++){ if(c1 == 3){funcf[ct]<<endl;c1=0;} funcf[ct] << xmagE[e1][e2][e3]*sin(pi*xphsE[e1][e2][e3]/180.0+ct*pi/8.0)<<" "; c1++;}}} c1=0; for(int e3=0;e3<idim;e3++){ for(int e2=0;e2<jdim;e2++){ for(int e1=0;e1<kdim;e1++){ if(c1 == 3){ funcf[ct]<<endl;c1=0;} funcf[ct] << ymagE[e1][e2][e3]*sin(pi*yphsE[e1][e2][e3]/180.0+ct*pi/8.0)<<" "; c1++;}}} c1=0; for(int e3=0;e3<idim;e3++){ for(int e2=0;e2<jdim;e2++){ for(int e1=0;e1<kdim;e1++){ if(c1 == 3){ funcf[ct]<<endl;c1=0;} funcf[ct] << zmagE[e1][e2][e3]*sin(pi*zphsE[e1][e2][e3]/180.0+ct*pi/8.0)<<" "; c1++;}}} c1=0; for(int e3=0;e3<idim;e3++){ for(int e2=0;e2<jdim;e2++){ for(int e1=0;e1<kdim;e1++){ if(c1 == 3){ funcf[ct]<<endl;c1=0;} funcf[ct] << xmagH[e1][e2][e3]*sin(pi*xphsH[e1][e2][e3]/180.0+ct*pi/8.0)<<" "; c1++;}}} c1=0; for(int e3=0;e3<idim;e3++){ for(int e2=0;e2<jdim;e2++){ for(int e1=0;e1<kdim;e1++){ if(c1 == 3){ funcf[ct]<<endl;c1=0;} funcf[ct] << ymagH[e1][e2][e3]*sin(pi*yphsH[e1][e2][e3]/180.0+ct*pi/8.0)<<" "; c1++;}}} c1=0; for(int e3=0;e3<idim;e3++){ for(int e2=0;e2<jdim;e2++){ for(int e1=0;e1<kdim;e1++){ if(c1 == 3){ funcf[ct]<<endl;c1=0;} funcf[ct] << zmagH[e1][e2][e3]*sin(pi*zphsH[e1][e2][e3]/180.0+ct*pi/8.0)<<" "; c1++;}}} } funcf[ct] << endl; funcf[ct].close(); }