How to deal with sstream and strstream inconsistencies from old compilers
I am temporarily using gcc 2.95.2 and instead of a header sstream
it defines (slightly different and outdated) strstream
. I currently work 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 gets really annoying. I just want to make sure that when I go back to a later gcc (or other compiler) I don't need to rewrite those passes. Any thoughts?
source to share
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 the title mystream.h
and mystream
.
If you really want to make it look like modern sstream, you can create a new class manually (using new c ++ std source code, or manually create a proxy class that uses strstream as the main way to work).
source to share