strstream is it safe for using

Jul 24, 2013 at 4:42am
Good morning all,
Is it safe to use use strstream. I just googled it, and most of them are saying to use stringstream. But unfortunately my environment is not supporting sstream.

Basically I am doing the following stuff in my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
char buffer[256];
strstream stream;

[code]for(count = 0; count < 30; ++count)
{
// how can i avoid this sprintf, format in the stream object itself
   sprint(buffer, "%3d", count); 
   stream << buffer << ' ' << ' ';
}

// Send it to the terminal for printing, i need char* here
terminal << stream.str()  // they are telling here it causes the memory leak

// now i want to clear stream, stream.clear() not works 

[/code]
Last edited on Jul 24, 2013 at 4:43am
Jul 24, 2013 at 5:27am
> Is it safe to use use strstream

Yes. But it is deprecated (may become unavailable after a future revision of the standard).


> how can i avoid this sprintf, format in the stream object itself

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <iomanip>
#include <strstream>

int main()
{
    std::ostrstream sstm ;

    for( int cnt = 0 ; cnt < 30 ; ++cnt ) sstm << std::setw(3) << cnt << ' ' ;
    sstm << std::ends ; // **** append a null character

    std::cout << sstm.str() ; // there is no memory leak
    // (sstm.rdbuf()->strmode == dynamic; destructor frees the memory)
}



> But unfortunately my environment is not supporting sstream.

The compiler is obsolete. Strongly suggest that you switch to a more recent version of the compiler/library.
Jul 24, 2013 at 5:50am
closed account (Dy7SLyTq)
stringstream is becoming deprecated???? NO!!! where did you read that? and is there an alternative?
Jul 24, 2013 at 5:51am
stringstream is becoming deprecated????


strstream is not stringstream.
Jul 24, 2013 at 5:52am
closed account (Dy7SLyTq)
oh... whats the difference?
sorry im tired and thought i read stringstream
Jul 24, 2013 at 9:52am
Thank you all :-)
Topic archived. No new replies allowed.