Unless there is something wrong with the following complete C++ file,
I think my quest to stream-ize our code will be at an end :(
#include <sstream>
#include <iostream>
using namespace std;
class linebuf : public streambuf
{
protected:
string buffer;
public:
virtual char overflow(char c) {if(c!=EOF) buffer+=c; return c;}
virtual streamsize xsputn(const char *s, streamsize num)
{
buffer.append(s ,num); return num;
}
virtual int sync()=0;
};
typedef unsigned int uint;
typedef bool (* FTYPE)(const void *,uint,uint,uin t);
class sendbuf : public linebuf
{
public:
virtual int sync() {cout << buffer << endl; buffer.erase(); return 0;}
};
class mystream : public std::ostream
{
protected:
sendbuf buf;
public:
mystream() : std::ostream(&b uf) {}
};
int main(void)
{
mystream s;
s << "Hello, " << "world!" << flush;
return 0;
}
g++, faithful and true companion that it is, compiles and runs this as
expected with all warnings enabled. Our Borland setup, however,
compiles this into an executable that crashes. So I figure either I'm
invoking some wicked implementation-defined (or undefined!) behavior
here, or our Borland setup is fatally flawed in ways that I cannot
begin to fathom. Thanks to everyone who provided assistance during my
travails - it was a great learning experience if nothing else!
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
I think my quest to stream-ize our code will be at an end :(
#include <sstream>
#include <iostream>
using namespace std;
class linebuf : public streambuf
{
protected:
string buffer;
public:
virtual char overflow(char c) {if(c!=EOF) buffer+=c; return c;}
virtual streamsize xsputn(const char *s, streamsize num)
{
buffer.append(s ,num); return num;
}
virtual int sync()=0;
};
typedef unsigned int uint;
typedef bool (* FTYPE)(const void *,uint,uint,uin t);
class sendbuf : public linebuf
{
public:
virtual int sync() {cout << buffer << endl; buffer.erase(); return 0;}
};
class mystream : public std::ostream
{
protected:
sendbuf buf;
public:
mystream() : std::ostream(&b uf) {}
};
int main(void)
{
mystream s;
s << "Hello, " << "world!" << flush;
return 0;
}
g++, faithful and true companion that it is, compiles and runs this as
expected with all warnings enabled. Our Borland setup, however,
compiles this into an executable that crashes. So I figure either I'm
invoking some wicked implementation-defined (or undefined!) behavior
here, or our Borland setup is fatally flawed in ways that I cannot
begin to fathom. Thanks to everyone who provided assistance during my
travails - it was a great learning experience if nothing else!
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Comment