help(about buffer)

B

berkay

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
 
J

John Harrison

berkay said:
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
 
J

Jim Langston

berkay said:
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.
 
T

TIT

berkay sade:
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::eek:stringstream ostrm(s);

but to answer your question:

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

TIT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Can't solve problems! please Help 0
Does someone want teamwork about programming 1
Help 1
bounded buffer 2
Help in hangman game 1
Strict aliasing and buffer handling 20
String buffer overruns? 8
Help with pointers 1

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top