 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
berkay Guest
|
Posted: Sat Oct 29, 2005 7:19 pm Post subject: help(about buffer) |
|
|
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
|
Posted: Sat Oct 29, 2005 7:43 pm Post subject: Re: help(about buffer) |
|
|
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
|
Posted: Sat Oct 29, 2005 7:47 pm Post subject: Re: help(about buffer) |
|
|
"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
|
Posted: Sat Oct 29, 2005 7:48 pm Post subject: Re: help(about buffer) |
|
|
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 |
|
 |
|
|
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
|
|