
On Wed, 15 Mar 2006, Delfin Rojas wrote:
The problem with your example was that after you read the first double there was a blank space in the input so you could not read the second double. Something like this will do:
istream& operator >> ( istream& in , vec& v ) { for ( int i = 0 ; i < vec::size ; ++ i ) if ((in >> v.data[ i ]) && !in.eof()) in.get(); return in ; }
As far as I know, when using operator>> on numbers (or any types supported
by the standard library), preceding spaces are skept, unless explicitly
told not to. Mm, after peeking a little more deeply in
I ran into another little problem while debugging your example so I thought I would mention it. Although the documentation does not explicitly say so you kind of make sense that lexical_cast expects the destination object's operator>> to use the complete output produced by the source object's operator<<. In other words:
stream << source stream >> target !!! stream.eof() must be true at this point
So if you try (like I did) lexical_cast<vec>("1 2 3") with vec.size = 2 it will fail.
I know that. Thanks for your help! -- François Duranleau LIGUM, Université de Montréal "The real source of wealth is correct ideas: workable ideas: that is, negative entropy -- Information." - Robert Anton Wilson, _Prometheus Rising_, 1983