This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Problem with ofstream in class member


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".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]