473,473 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

strstream depreciation

Hi,

I have an application that uses 'strstream' in just under half its .cc
files, about 10 files.

What is the replacement for 'strstream' ?
What are my options for replacing it ?

Many thanks in advance,

Aaron
Aug 14 '05 #1
10 14847
In article <42***********************@ptn-nntp-reader03.plus.net>,
"Aaron Gray" <aa********@gmail.com> wrote:
Hi,

I have an application that uses 'strstream' in just under half its .cc
files, about 10 files.

What is the replacement for 'strstream' ?
What are my options for replacing it ?

Many thanks in advance,

Aaron


Try one of:

ostringstream
istringstream
stringstream

which are all in the header <sstream>.

The chances aren't bad that a simple find/replace will get you going
without a hitch. The main difference is that the stringstream family
doesn't expose its internal buffer and is thus less susceptible to
memory leaks.

strstream is deprecated because it is memory leak prone. That is not to
say that correct usage of it might result in a memory leak, just that it
is so easy to misuse it, resulting in a memory leak.

That being said, strstream fulfills a role that has not yet been
replaced in the std::lib: The ability to specify the buffer which the
read/write interacts with. If you need to specify the buffer (say for
performance reasons or whatever), the stringstream family will not do it
for you. There is no alternative in the std::lib for this application.

Although strstream has been deprecated for nearly a decade, I don't
anticipate removing it from C++0X because of the lack of covering the
above mentioned functionality. I have no doubt that a better facility
could be designed for this functionality, but no one to date has
proposed anything.

-Howard
Aug 14 '05 #2
> Try one of:

ostringstream
istringstream
stringstream

which are all in the header <sstream>.

That being said, strstream fulfills a role that has not yet been
replaced in the std::lib: The ability to specify the buffer which the
read/write interacts with. If you need to specify the buffer (say for
performance reasons or whatever), the stringstream family will not do it
for you. There is no alternative in the std::lib for this application.
Right this is its main usage.
Although strstream has been deprecated for nearly a decade, I don't
anticipate removing it from C++0X because of the lack of covering the
above mentioned functionality. I have no doubt that a better facility
could be designed for this functionality, but no one to date has
proposed anything.


Maybe I will come up with some replacement code for ths app then.
Ether that or keep strstream and like it and lump it.

I can just ignore it for now and use a '-Wno-deprecated' switch.

Thanks for your explanation.

Aaron
Aug 15 '05 #3
Aaron Gray wrote:
Try one of:

ostringstream
istringstream
stringstream

which are all in the header <sstream>.

That being said, strstream fulfills a role that has not yet been
replaced in the std::lib: The ability to specify the buffer which the
read/write interacts with. If you need to specify the buffer (say for
performance reasons or whatever), the stringstream family will not do it
for you. There is no alternative in the std::lib for this application.


Right this is its main usage.
Although strstream has been deprecated for nearly a decade, I don't
anticipate removing it from C++0X because of the lack of covering the
above mentioned functionality. I have no doubt that a better facility
could be designed for this functionality, but no one to date has
proposed anything.


Maybe I will come up with some replacement code for ths app then.
Ether that or keep strstream and like it and lump it.

I can just ignore it for now and use a '-Wno-deprecated' switch.

Thanks for your explanation.

Aaron


stringstream does allow you to specify a buffer, e.g.

std::string str;
char * pCh;

// put stuff into 'str'...
// make 'pCh' point to some char array...

// make a stringstream from a COPY of 'str'
std::stringstream s1(str);
// make a stringstream from a COPY of '*pCh'
std::stringstream s2(pCh);
// make a stringstream from a COPY of "hello there"
std::stringstream s3("hello there");

s1, s2, and s3 make a std::stringstream using a COPY
of the data specified by their constructor arg.

One can not create a stringstream that access a fixed
address as its string buffer (e.g. some specific memory
address) because stringstream always makes a COPY of
any string arg passed to its constructor.
Aug 15 '05 #4

"Aaron Gray" <aa********@gmail.com> wrote in message
news:42***********************@ptn-nntp-reader03.plus.net...
Try one of:

ostringstream
istringstream
stringstream

which are all in the header <sstream>.

That being said, strstream fulfills a role that has not yet been
replaced in the std::lib: The ability to specify the buffer which the
read/write interacts with. If you need to specify the buffer (say for
performance reasons or whatever), the stringstream family will not do it
for you. There is no alternative in the std::lib for this application.


Right this is its main usage.
Although strstream has been deprecated for nearly a decade, I don't
anticipate removing it from C++0X because of the lack of covering the
above mentioned functionality. I have no doubt that a better facility
could be designed for this functionality, but no one to date has
proposed anything.


Maybe I will come up with some replacement code for ths app then.
Ether that or keep strstream and like it and lump it.


You might want to take a look at the boost IOStreams library at:
http://www.boost.org/libs/iostreams/doc/index.html.

In particular see array_source, array_sink, and array devices for input,
output and io streams respectively.
....

#include <boost/iostreams/device/array.hpp>

....

using namespace boost::iostreams;

char* dataptrx = new char[datasize];

stream<array> io( dataptr, datasize );

io << 123;

int an_int = 0;

io>> an_int;

....
Jeff Flinn
Aug 15 '05 #5
Aaron Gray wrote:

Maybe I will come up with some replacement code for ths app then.
Ether that or keep strstream and like it and lump it.

If your application works, don't change it just because of some vague
fear that this class might go away in the future. Wait and see. It might
never need changing.
I can just ignore it for now and use a '-Wno-deprecated' switch.


Massively rewriting correct, working code to avoid a warning is a waste
of time.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Aug 15 '05 #6
> stringstream does allow you to specify a buffer, e.g.

The app writes to the buffer using streams then reads the written buffer :(

Aaron
Aug 15 '05 #7
>> Maybe I will come up with some replacement code for ths app then.
Ether that or keep strstream and like it and lump it.


If your application works, don't change it just because of some vague fear
that this class might go away in the future. Wait and see. It might never
need changing.


okay, thanks.
I can just ignore it for now and use a '-Wno-deprecated' switch.


Massively rewriting correct, working code to avoid a warning is a waste of
time.


Thanks,

Aaron
Aug 15 '05 #8
> You might want to take a look at the boost IOStreams library at:
http://www.boost.org/libs/iostreams/doc/index.html.

In particular see array_source, array_sink, and array devices for input,
output and io streams respectively.
...

#include <boost/iostreams/device/array.hpp>

...

using namespace boost::iostreams;

char* dataptrx = new char[datasize];

stream<array> io( dataptr, datasize );

io << 123;

int an_int = 0;

io>> an_int;

...


Okay thanks, I will look into that.

Aaron
Aug 15 '05 #9
Aaron Gray wrote:
stringstream does allow you to specify a buffer, e.g.


The app writes to the buffer using streams then reads the written buffer :(

Aaron


That's fine. That's what stringstream is for.
We do that all of the time:

1) create a stringstream (often as a member of an object)
2) write to the stringstream
3) read from the stringstream.

Larry
Aug 15 '05 #10
> That's fine. That's what stringstream is for.
We do that all of the time:

1) create a stringstream (often as a member of an object)
2) write to the stringstream
3) read from the stringstream.


Ah :)

Thats a bit obvious now :)

Thanks.

Aaron
Aug 16 '05 #11

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

Similar topics

1
by: Bpb | last post by:
I'm trying to use a string stored in a strstream object as the filename parameter in the open call on an fstream object.. It requires a const char* but no matter what I try I can't seem to get a...
4
by: vishnu mahendra | last post by:
Can anyone please tell me what is the use of "strstream.h" header file and the functions in "strstream.h". where can i find documentation for that header file. thankyou in advance, vishnu.
6
by: vishnu mahendra | last post by:
hello to all, #include<iostream.h> #include<conio.h> #include <strstream.h> void main() { clrscr(); strstream str; char *a = new char; int i;
2
by: nejmay | last post by:
Help Please, I am taking a beginners VB.NET class and my next assignment making a Depreciation Calculator. I am suppose to use the built in functions SLN() and SYD() to perform the calus, option...
2
by: blagdam | last post by:
I am attempting to calculate the book value of assets in a query. I calculate total depreciation of the asset using the built in Strait Line Depreciation function and then use the following...
5
by: nithya4u | last post by:
I am working on a c++ module, where large amount of data needs to be written to a stream and str() method is been used to assign the value of this to the char*. This produces the intended result....
4
by: morten44 | last post by:
here the output and my Compiler version, It is a basic example from Bjarne Stroustrups homepage, morten@Westparkstr42:~/Bjarne_Stroustrup/06_Chapter_06$ g++ dc_except.c...
3
by: LosLobo | last post by:
Good morning all. This is my first post to the site, and what a wonderful site this is. I wish I had come across it years ago. I am working on a database that is going to track the assets for a...
2
by: bossenb6 | last post by:
I have an assignment to calculate depreciation using straight line, double declining balance and sum of the years digits. Heres what I have so far, but I can't seem to figure it out. Please help!! ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.