Problem with ofstream in class member

Simon A. Crase simon@icpdd.neca.nec.com.au
Wed Jan 28 16:00:00 GMT 1998


I have run into a problem with ofstream (Cygnus b18 compiler), so I wonder if anyone has seen it before and, if so, whether they have a better fix than the one I found.

I have a class that looks like this:

class Stuff
{

private:
  ofstream mystream;
};

I open mystream with a file name, try to write to the file, & the program falls over.  According to gdb, the culprit is the line:

  mystream << some_stuff << endl;

This happens regardless of the data type of some_stuff.

Last night I moved the declaration of mystream out of the class & put it into the function that was doing the writing:

     ofstream mystream("myfile);
     mystream << some_stuff << endl;
     mystream.close();

And the program works fine.  Except I need to rework my design somewhat, as my current design looks like:

1. open the stream;
2. write to it from several differnet functions;
3. close.

So I can work around the problem by:
1. Create a container;
2. Gradually add the stuff I was planning to write.
3. Open stream, pour the contents of the container into it, close stream.

So, has anyone else seen this problem & come up with a better solution they would be willing to share?


Simon A. Crase
-- 


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list