473,385 Members | 1,356 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,385 software developers and data experts.

Streambuf and streams

Hello!
Im trying to get a memstream object to work but it seems that I miss
something!
My expectation is to have one stream for input and another for output!
I also expect the streambuf to handle the allocation and deallocation of
memory automaticly!
Is it possible?
I have some C++ books but they all has poor coveridge on this topic!

Any examples on this topic!
..or help!
Here is my snippet!
It compiles and executes but the output is 'Count 0'
-----------------------------------------------------------
class CMemStream : public basic_streambuf<UCHAR,char_traits<UCHAR> >
{
public:
typedef basic_istream<UCHAR, char_traits<UCHAR> > In;
typedef basic_ostream<UCHAR, char_traits<UCHAR> > Out;
};

void Test()
{
CMemStream b;
CMemStream::Out o(&b);
CMemStream::In i(&b);
o << 0x41;
cout << "Count " << i.gcount() << endl;
}

-----------------------------------------------------------
...Henry
Jul 22 '05 #1
1 1383
On Tue, 31 Aug 2004 15:29:03 GMT, "Henry" <no**********@hotmail.com>
wrote:
Hello!
Im trying to get a memstream object to work but it seems that I miss
something!
My expectation is to have one stream for input and another for output!
I also expect the streambuf to handle the allocation and deallocation of
memory automaticly!
Is it possible?
I have some C++ books but they all has poor coveridge on this topic!

Any examples on this topic!
.or help!
Lots of info here (and you should buy the book)
http://www.langer.camelot.de/IOStrea...cerpt.htm#Main
Here is my snippet!
It compiles and executes but the output is 'Count 0'
-----------------------------------------------------------
class CMemStream : public basic_streambuf<UCHAR,char_traits<UCHAR> >
{
public:
typedef basic_istream<UCHAR, char_traits<UCHAR> > In;
typedef basic_ostream<UCHAR, char_traits<UCHAR> > Out;
};

void Test()
{
CMemStream b;
CMemStream::Out o(&b);
CMemStream::In i(&b);
o << 0x41;
cout << "Count " << i.gcount() << endl;
}


You have a couple of problems. First of all, streams don't necessarily
work well with UCHAR (due to char_traits<UCHAR> possibly being
undefined). You should probably stick to char. Secondly, your
CMemStream doesn't actually do anything - you need to override virtual
functions like overflow, sync, underflow, etc. in order for it to have
any functionality.

But all this is quite hard; an easier way is to use a library, such
as:
http://home.comcast.net/~jturkanis/iostreams/
(it is being reviewed for inclusion in the boost libraries at the
moment, www.boost.org)

Tom
Jul 22 '05 #2

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

Similar topics

4
by: Matt Chaplain | last post by:
Hi there. I'm writing a program that uses the Telnet protocol over TCP/IP sockets. Of course, that has no bearing here, so I'll rephrase that in Standard C++ :) In essense, I'm trying to...
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...
5
by: Christopher Benson-Manica | last post by:
Yes, it's me again, with my dear, dear friends std::streambuf and std::ostream... On the bright side, the code compiles. On the gloomy side, I can't seem to get overflow() or xsputn() called... ...
4
by: Christopher Benson-Manica | last post by:
Is there any way to prevent the streambuf from calling overflow or xsputn unless I specifically flush the stream? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I...
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...
9
by: Marcin Kalicinski | last post by:
Hi, I have a set of C-like functions for file access (like fopen, fwrite, fread, fseek etc.). But I want to access the files using C++ stream, not these functions. What I probably need to do is...
4
by: mathieu | last post by:
Hello, Browsing the archive of this group I see that the c++ iostream wrapper that are shipped with zlib are not satisfying : ...
7
by: Christopher Pisz | last post by:
I found an article http://spec.winprog.org/streams/ as a starting point, but it seems to do alot of things that aren't very standard at all. One particular problem is, that he is using a vector as...
1
by: Christopher Pisz | last post by:
I am trying to empty and reset my internal buffer in my derived sync method. Am I correct in assuming I can call setp( std::streambuf::pbase(), std::streambuf::pbase()); to reset the internal...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.