Subj : Re: fstream arrays To : borland.public.cpp.borlandcpp From : "D Kat" Date : Wed Mar 10 2004 01:07 pm OK, you have all convinced me that the code is legit.... These are DOS experiments that I'm running and the only thing left is the fact that I'm using Borland 3.0 for compiling and I have never entirely understood the option settings on it.... Thanks again for the help, lessons and insight. DKat " Bruce Salzman" wrote in message news:403d1e42$1@newsgroups.borland.com... > > if(!out_files[i]) ...... tests as 1 or as an ERROR > > if(!out_file).... tests as 0 or NOT ERROR. > > > > ofstream outfiles; > > vs > > ofstream outfiles[3]; > > > > Why does one return false while the other doesn't - BOTH > successfully > > open, write and save. > > I can't reproduce what you are seeing. How many files are you trying to > open? There is no real diffence between the single stream and the array > version you cite except the latter opens 3 streams instead of one. > > Here is the code I tested (which does not show any error messages): > #include > > #define NSUB 10 > char *cdn="txt"; > char *sub_name[NSUB]={ > "FILE1", "FILE2", "FILE3", "FILE4", "FILE5", "FILE6", "FILE7", > "FILE8", "FILE9", "FILE10", > }; > ofstream out_files[NSUB];//file to write data to > > int get_subj_fp(int file) > { > char name[20]; > > strcpy(name,"./data/"); > strcat(name, sub_name[file]); > strcat(name,"."); > strcat(name,cdn); > out_files[file].open(name); > if (!out_files[file]) > { > cerr << "\nerror on file " << sub_name[file] << "\n"; > return(1); > } > return 0; > } > > int main(int argc, char* argv[]) > { > int i; > for (i=0; i< NSUB; i++){ > get_subj_fp(i); > } > for (i=0; i< NSUB; i++){ > out_files[i] << "hello, world\n"; > } > return 0; > } > > Regards, > Bruce > > .