473,324 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

More problems inheriting from streambuf

This is starting to seem ridiculous to me :(

#include <streambuf>
#include <iostream>

class
TWFileStream : public std::streambuf
{
private:
char cbuf[2];

protected:
TLSFile lsf;
virtual int_type overflow (int_type c)
{
*cbuf=c;
if(!LastOpSucceeded||!(LastOpSucceeded=lsf.Write(c buf)))
return(EOF); return(c);
}
virtual std::streamsize xsputn(const char *s, std::streamsize num)
{
lsf.Write(s);return(0);
}
};

If there's nothing wrong with the above definition, *why* am I getting
errors about "operator<< not implemented in type TWFileStream"? I
thought that was the whole grand goal of this plan to inherit from
streambuf? *sigh*

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #1
3 2152

"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in message
news:c1**********@chessie.cirr.com...
This is starting to seem ridiculous to me :(

#include <streambuf>
#include <iostream>

class
TWFileStream : public std::streambuf
{
private:
char cbuf[2];

protected:
TLSFile lsf;
virtual int_type overflow (int_type c)
{
*cbuf=c;
if(!LastOpSucceeded||!(LastOpSucceeded=lsf.Write(c buf)))
return(EOF); return(c);
}
virtual std::streamsize xsputn(const char *s, std::streamsize num)
{
lsf.Write(s);return(0);
}
};

If there's nothing wrong with the above definition, *why* am I getting
errors about "operator<< not implemented in type TWFileStream"? I
thought that was the whole grand goal of this plan to inherit from
streambuf? *sigh*


Need to go back to the book I think.

TWFileStream is not a stream, and doesn't have operator<< defined. It's a
streambuf which must be attached to an ostream object.

TWFileStream buffer;
ostream stream(&buffer);
stream << "some string";

Normally you wrap this in a class

class TWFileStreamItIsReally : public std::ostream
{
public:
TWFileStreamItIsReally()
{
rdbuf(&buffer);
}
private:
TWFileStream buffer;
};

john
Jul 22 '05 #2
Christopher Benson-Manica escribió:
If there's nothing wrong with the above definition, *why* am I getting
errors about "operator<< not implemented in type TWFileStream"? I
thought that was the whole grand goal of this plan to inherit from
streambuf? *sigh*


You need to write your own streambuf, and your own stream that uses this
streambuf. There is a detailed sample at:
http://www.informatik.uni-konstanz.de/~kuehl/iostream/

Regards.
Jul 22 '05 #3
John Harrison <jo*************@hotmail.com> spoke thus:
TWFileStream is not a stream, and doesn't have operator<< defined. It's a
streambuf which must be attached to an ostream object.
Yep, that's in the book... sorry to trouble you, although on the
bright side I think this is finally starting to make sense :)
Normally you wrap this in a class class TWFileStreamItIsReally : public std::ostream
{
...
};


I see, I'm in the process of doing that now, although I've made it a
template class so I can do different things with the buffer. Is that
a good idea?

*sigh* Only 13 compile errors to go, and then I get to find out that
it doesn't work anyway ;(

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Viktor Lundström | last post by:
Hi! I was planning to wrap a socket inside an iostream, to achieve something like this: TCPSocket s(..); s << "Hello!" << endl; Information on the web seems to be a bit scarce on how to do...
8
by: Christopher Benson-Manica | last post by:
I know I keep asking similar questions, but I really want to do this at least sort of right. Not to mention I got no on-group replies to my previous post :( I desperately want an interface that...
9
by: Fred Ma | last post by:
Hello, I posted previously under the thread: How to break this up into streambuf/ostream I've asked our library to get "C++ IOStreams and Locales..." by A. Langer et al. Meantime, I've...
4
by: Thomas Matthews | last post by:
Hi, My objective is to add enable & disable functionality to the ofstream class. I want to have a log file where I can disable and enable output to it. When my first tests pass, I want to...
1
by: Bovine | last post by:
I've recently been using a class for directing output to both a file and the screen. I copied it from this website: http://www.talkaboutprogramming.com/group/comp.lang.c++/messages/812299.html...
7
by: smith4894 | last post by:
Hello all, I'm working on writing my own streambuf classes (to use in my custom ostream/isteam classes that will handle reading/writing data to a mmap'd file). When reading from the mmap...
2
by: renagade629 | last post by:
Can anybody help me understand what i'm doing wrong or what I'm missing? Is there anyother good and commendable C++ program I can use (free) from the internet like Dev C++? I'm having trouble doing...
4
by: rakesh.usenet | last post by:
For a particular application of mine - I need a simulation of byte array output stream. * write data onto a stream * getback the contiguous content as an array later for network transport. ...
3
by: Raymond Martineau | last post by:
I have the following code segment for a class intended to split output between cout and a file: class SplitStream : public std::streambuf { std::streambuf *x; public: SplitStream() {
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.