Subj : Re: fstream arrays To : borland.public.cpp.borlandcpp From : "D Kat" Date : Wed Mar 10 2004 12:43 pm You cannot have an array of 1 (ofstream outfiles[1] is illegal) ... I do absolutely noting different in the code other than if I am running an experiment that only uses 1 Subject (or there is only one data file that is saved) then I define outfiles to not be an array where in experiments in which I run more than one subject (having more than one data file that needs to be saved) I define the ofstream as an array. The multiple opening of files is put in a simple for loop - for ( sub = 0 ; sub < MAXSUB ; sub ++) .... same code but out_files is now out_files[sub]. This is what I find baffling. The code is the same except for the issue of it being an array item. In trying to debug I have eliminated the loop and used the exact same code as with a single subject but replaced ofstream outfiles with ofstream outfiles[2] and out_files with out_files[0]; The first gives not error the second does. "Thomas Maeder [TeamB]" wrote in message news:m2d682x0xw.fsf@madbox2.local... > "D Kat" writes: > > > The error (and I have stepped through this as well) is done within the > > function get_subj_fp - I have taken out the error check on the return of the > > function because it doesn't matter - what I'm saying is ignore the fact that > > I don't care if I get an error or not. That is not the point. In my way of > > veiwing the world Arrays are pointers. > > You should change your view then. Arrays and pointers are totally different > things. The only thing that relates them to each other is that an array > is implicitly converted into a pointer to its first element when necessary. > > > > That is how I refer to them. This > > is what I care about > > > > 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. > > There is no conceptual difference between an ofstream that is an array > element and an ofstream that isn't. You seem to do something differently > when dealing with the array. > > > Consider starting with a simple ofstream. Then change it into an array of > 1 (one) ofstream; simply add [1] in its definition and [0] wherever you > use it. Then replace the [1] by a [nrOfStreams] (with nrOfStreams being > a constent unsigned int of value 1) and the [0] by loops from 0 to > nrOfStreams (not inclusive). Then increase nrOfStreams to the value you > need it to have. .