Is this a libstdc++ bug?
#include <string>
#include <sstream>
using namespace std;
int main() {
basic_string<char16_t> str(u"0.0");
basic_stringstream<char16_t> sstr(str);
double x = 9;
sstr >> x;
}
Output, under GCC 4.8 Linux x86_64:
$ ./main
terminate called after throwing an instance of 'std::bad_cast'
what(): std::bad_cast
Aborted (core dumped)
Edit Can someone suggest a way to make this function work under GCC 4.9 without changing its signature:
template<typename T>
T fromString(std::basic_stringstream<char16_t>& stream)
{
T v;
stream >> v;
return v;
}
Typical use is:
std::basic_string<char16_t> string(...);
std::basic_stringstream<char16_t> sstream(string);
double v = fromString<double>(sstream);
char16_t
orchar32_t
, onlychar
andwchar_t
. – Maraudingstd::basic_string<char16_t> s; stream >> s;
produces the same exception. – Addictive