Boost logo

Boost :

From: Sven Johannsen (Sven.Johannsen_at_[hidden])
Date: 2002-03-21 06:56:26


the following two lines raise a bad_cast-exception

std::wstring str= L"3.14";
double pi = boost::lexical_cast<double>(str);

With a look inside the lexical_cast implementation i found a std::stringstream.

A std::stringstream is a typedef to a basic_stringstream<char,
char_traits<char>, allocator<char> >, but in this case i need a
basic_stringstream<wchar_t, ...>

As a first fix i changed lexical_cast to

template<typename Target, typename Source>
                Target lexical_cast(const Source* arg) // the '*' is the change
{
         //std::stringstream interpreter;

std::basic_stringstream<Source,
std::char_traits<Source>,std::allocator<Source> > interpreter;
...
}

Now i have to write

double pi = boost::lexical_cast<double>(str.c_str());

This is not the behaviour i want to have.

Any Idea?

Sven


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk