S
Scott
Hi All,
I have a C++ program that uses a library. This library (which I also
wrote in C++), writes a series of status messages to clog as it goes about
its work. In my program which utilizes this library, I am attempting to
redirect clog to a stringstream, to allow me to output the status info as
I decide it is necessary. So, I have this in my program:
// redirect clog
stringbuf *buf;
stringstream ss;
buf = ss.rdbuf();
clog.rdbuf( buf );
It works fine, but the program segfaults. I did a bit of research, and it
seems that the problem may be that the flush of the global stream objects
at the end of the program is trying to access an already destructed
stringbuf. Does this sound correct? And if it is, how do I go about
fixing it? It seems that no object I create will live long enough to see
the destruction of clog. If this doesn't sound like the culprit, could
anyone else suggest something? If I comment out those lines, the segfault
goes away (and clog is output normally to stdout).
On another note, is this a reasonable means of design for my library (i.e.
writing to clog, and then expecting a user to override this if they wish
to redirect the output)?
Thanks for any assistance!
Best,
Scott
I have a C++ program that uses a library. This library (which I also
wrote in C++), writes a series of status messages to clog as it goes about
its work. In my program which utilizes this library, I am attempting to
redirect clog to a stringstream, to allow me to output the status info as
I decide it is necessary. So, I have this in my program:
// redirect clog
stringbuf *buf;
stringstream ss;
buf = ss.rdbuf();
clog.rdbuf( buf );
It works fine, but the program segfaults. I did a bit of research, and it
seems that the problem may be that the flush of the global stream objects
at the end of the program is trying to access an already destructed
stringbuf. Does this sound correct? And if it is, how do I go about
fixing it? It seems that no object I create will live long enough to see
the destruction of clog. If this doesn't sound like the culprit, could
anyone else suggest something? If I comment out those lines, the segfault
goes away (and clog is output normally to stdout).
On another note, is this a reasonable means of design for my library (i.e.
writing to clog, and then expecting a user to override this if they wish
to redirect the output)?
Thanks for any assistance!
Best,
Scott