lexical_cast with tuple target fails.

Should it be possible to do a lexical_cast to a tuple if tuple_io.hpp is included? It turns out that it doesn't work. The following example will throw bad_lexical_cast: #include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple_io.hpp> #include <boost/lexical_cast.hpp> #include <iostream> #include <sstream> #include <string> using namespace std; typedef boost::tuple<unsigned,unsigned,unsigned> point; int main() { string s = "(1 2 3)"; point p; stringstream iss; if (!(iss << s).fail()) { if (iss >> p && iss.get() == char_traits<char>::eof()) cout << p << endl; } // throws here: p = boost::lexical_cast<point>(s); cout << p << endl; return 0; }

Bryan Green <bryan.d.green <at> nasa.gov> writes:
string s = "(1 2 3)"; point p; stringstream iss;
It's covered by FAQ http://www.boost.org/doc/libs/1_35_0/libs/conversion/lexical_cast.htm#faq Try inserting 'iss >> noskipws;' here.
if (!(iss << s).fail()) { if (iss >> p && iss.get() == char_traits<char>::eof()) cout << p << endl; }
Can you please submit a bug and assign it to the tuple maintainer? -- Alexander

Alexander Nasonov writes:
Bryan Green <bryan.d.green <at> nasa.gov> writes:
string s = "(1 2 3)"; point p; stringstream iss;
It's covered by FAQ http://www.boost.org/doc/libs/1_35_0/libs/conversion/lexical_cast.htm#faq
Try inserting 'iss >> noskipws;' here.
if (!(iss << s).fail()) { if (iss >> p && iss.get() == char_traits<char>::eof()) cout << p << endl; }
Can you please submit a bug and assign it to the tuple maintainer?
Thanks, I had overlooked that in the FAQ. http://svn.boost.org/trac/boost/ticket/1920 -bryan
participants (2)
-
Alexander Nasonov
-
Bryan Green