C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

help(about buffer)

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
berkay
Guest





PostPosted: Sat Oct 29, 2005 7:19 pm    Post subject: help(about buffer) Reply with quote



i have a string s1 and if i want to make such a thing
strstreambuf bbuf(char*,int);
it only accepts a pointer and i have a string how can i do this i ll be
happy if u can help me

Back to top
John Harrison
Guest





PostPosted: Sat Oct 29, 2005 7:43 pm    Post subject: Re: help(about buffer) Reply with quote



berkay wrote:
Quote:
i have a string s1 and if i want to make such a thing
strstreambuf bbuf(char*,int);
it only accepts a pointer and i have a string how can i do this i ll be
happy if u can help me


Why on earth do you want to make a strstreambuf? It's a really unusual
type of object to want to make, normally it is only made behind the
scenes by other classes.

Anyway the bad news it that you can't make a strstreambuf from a string,
only from a char pointer.

I expect that what you really want to make is a istringstream, like this

string str = ...;
istringstream buf(str);

Perhaps you should explain what you are trying to do instead of what you
think you want and I could help better.

john

Back to top
Jim Langston
Guest





PostPosted: Sat Oct 29, 2005 7:47 pm    Post subject: Re: help(about buffer) Reply with quote



"berkay" <berkay.beygo (AT) gmail (DOT) com> wrote

Quote:
i have a string s1 and if i want to make such a thing
strstreambuf bbuf(char*,int);
it only accepts a pointer and i have a string how can i do this i ll be
happy if u can help me


If the bbuf doesn't change the string, you can pass sl.c_str() but this is a
const pointer. So you would have to const_cast it const_cast<char*>(
sl.c_str() ) BUT, make 10000% sure that bbuf does NOT change the data.

Now, if it does it is possible to pass sl.data() which is not const, it can
be changed, but it is a fixed length buffer, make sure your bbuf doesnt' try
to write past the end of it.




Back to top
TIT
Guest





PostPosted: Sat Oct 29, 2005 7:48 pm    Post subject: Re: help(about buffer) Reply with quote

berkay sade:
Quote:
i have a string s1 and if i want to make such a thing
strstreambuf bbuf(char*,int);
it only accepts a pointer and i have a string how can i do this i ll be
happy if u can help me


Why use the deprecated strstream and not the newer stringstreams
(<sstream>)?

basic_stringbuf<char> buf(s1);

or even more convenient:

std::istringstream istrm(s);
std::ostringstream ostrm(s);

but to answer your question:

std::strstreambuf bbuf(s1.c_str(),s1.size());

TIT

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.