473,783 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
+ 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 14885
In article <42************ ***********@ptn-nntp-reader03.plus.n et>,
"Aaron Gray" <aa********@gma il.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::stringstre am s1(str);
// make a stringstream from a COPY of '*pCh'
std::stringstre am s2(pCh);
// make a stringstream from a COPY of "hello there"
std::stringstre am s3("hello there");

s1, s2, and s3 make a std::stringstre am 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********@gma il.com> wrote in message
news:42******** *************** @ptn-nntp-reader03.plus.n et...
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::iostream s;

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::iostream s;

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

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

Similar topics

1
2254
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 raw pointer to the string stored in the strstream object.. Anyone have an idea I'm overlooking? Thanks in advance.. -- http://www.SPAMdelusionalmindSUCKS.com
4
1996
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
2861
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
2813
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 buttons to specify the deprec method, combo box to specify life. Then I am suppose to display the depreciation schedule in ListView. I am having a hard time understanding how to tie the ListView with the actual calulation and make the columns and...
2
5666
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 statement to calculate BookValue: BookValue: - which works fine. The problem that I have is that when the asset's book value goes negative, the value in the query doesn't stop at zero. Is there a way to prevent the value in a calculated query field...
5
3742
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. But when i run purify on it i get the following results. MLK: Memory leak of 8656 bytes from 9 blocks allocated in strstreambuf::doallocate(void) Distribution of leaked blocks 987 bytes from 1 block of 987 bytes (0x03977ea8) 980 bytes from 1...
4
7295
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 dc_except.c:197:23: error: strstream.h: No such file or directory g++ -v Using built-in specs.
3
5995
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 non-profit organization. One of the aspects which they wish to have happen is to have the database auto-calculate the depreciation value of any given asset (straight-line). I have done several searches on this topic and in a previous post in the...
2
6246
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!! public class LabTest1Initialize { public static void main(String args) { // declare an integer (array) array with 6 rows (6 assets) // & 5 columns (5 attributes for each asset) int assetInfo = new int ;
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10081
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7494
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4044
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 we have to send another system
2
3643
muto222
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.