
François Duranleau wrote:
If I read the documentation correctly about boost::lexical_cast, for a convertion between two types to work, the source type must be OutputStreamable and the target type must be InputStreamable (plus some other requirements about copying and default construction).
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 ; } 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. Hope this helps, -delfin