I don't know. I use stringstream for all types of conversion
and it works. What real advantage would istringstream give
me?
It seems clearer to me if you're only going to be reading. I
use istringstream for input conversions (from text to whatever),
and ostringstream for output conversions (to text from
whatever). Somehow, it just seems clearer to say up front what
I'm going to do.
[...]
std::string str_array = "{201,23,240,56,23,45,34,23}";
std::stringstream Buffer;
Buffer << str_array;
Why those two lines, instead of simply:
std::istringstream Buffer( str_array ) ;
Becuase I normally use stringstring in one of my templates:
template<typename T, typename F > T StrmConvert( const F from )
{
std::stringstream temp;
temp << from;
T to = T();
temp >> to;
return to;
}
Sort of boost::lexical_cast, in sum. That's a different
context. (I'm not totally convinced that boost::lexical_cast is
a good idea. I'm not too hot on the idea that you can convert
anything to anything else, and never get a compiler error.)
std::string temp( from );
then I get compiler warnings at times depending on F.
warning C4244: 'argument' : conversion from 'const float' to
'std::_Iosb<_Dummy>:

penmode', possible loss of data
and I go for 0% warnings in my code. I know that the form I
use doesn't give any warnings.
One could argue that since you're doing two conversions, you
should have two conversion objects, i.g.:
std::istringstream in ;
in << from ;
std:

stringstream out( in.str() ) ;
T to ;
out >> to ;
return to ;
I'm not sure. As I said, I'm not too hot on this idea to begin
with. (If I were doing it, I'd certainly add a lot of error
handling. But I presume you've just stripped it out to make it
shorter for posting.)
Agreed, but in most instances where I'm using stringstream for
conversion I've verified the data before I try to convert it,
or the output makes it obvious there was a problem.
In most cases, I have too. Nothing like boost::regex
beforehand, to know what I'm dealing with. (But I thought I'd
mentionned that.) If you don't know the length in advance,
however, it's probably easier to do the checking dynamically.
I don't know the full context either. It might be worth
considering creating a decorator type for which you define an
operator>>, and use that, something like:
source >> ArrayReader( array ) ;
With user input data I would definately do syntax checking of
the string before/during/after the conversion.
This is really not needed though, unless there is extraneous data after
the ) such as
etc...
Yes. The real question is whether the string has been format
checked before hand, or not. If it has, then no further
checking should be necessary. If it hasn't, you probably want
to verify everything.