This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
Problem with ofstream in class member
- To: gnu-win32 at cygnus dot com
- Subject: Problem with ofstream in class member
- From: simon at icpdd dot neca dot nec dot com dot au (Simon A. Crase)
- Date: Thu, 29 Jan 1998 11:00:01 +1100 (EST)
- Reply-To: simon at icpdd dot neca dot nec dot com dot au
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".