views:

585

answers:

1

I'm temporarily using gcc 2.95.2, and instead of having a sstream header, it defines a (slightly different, and deprecated) strstream. I'm currently getting around this with

#if __GNUC__ < 3       // or whatever version number it changes
#include <strstream>
#else
#include <sstream>
#endif

and then things like:

#if __GNUC__ < 3
    strstream str;
    str << "Hello World";
#else
    stringstream str("Hello World");
#endif

but it's getting really annoying. I just want to make sure that when I switch back to a more recent gcc (or some other compiler), I don't have to rewrite these passages. Any thoughts?

+2  A: 

Create mystream.h as

#ifndef mystream

#if __GNUC__ < 3       // or whatever version number it changes
#include <strstream>
#define mystream(x,y) strstream x; x << y;
#else
#include <sstream>
#define mystream(x,y) sstream x(y);
#endif

#endif

Then use mystream.h header and mystream type instead.

If you really want to make it look like modern sstream, you can create a new class manually (with the help of newer std c++ library source code or manually creating a proxy class that uses strstream as the underlying way to work).

Mehrdad Afshari
I've thought about this, but I really want the code to basically look like the modern stringstream, and there are some minor syntactical differences.
Jesse Beder
I've decided to go with creating a stringstream class that is implemented using strstream.
Jesse Beder
This is the way I'd choose personally :)
Mehrdad Afshari