I'm trying to process UTF-16 string (placed in a buffer buf
) with the help of std::basic_string
and istringstream
. An exception std::bad_cast
occurs in this code. Is there a problem with my code? Or gcc's STL just cannot handle unsigned int
(16 bit) symbols?
const unsigned short * buf;
// ... fiilling buf
std::basic_string<unsigned short> w(buf);
std::basic_istringstream<unsigned short> iss(w);
unsigned int result;
try { iss >> result; }
catch (std::exception& e)
{
const char * c = e.what();
}
The same code with std::wstring
and std::wistringstream
works correctly.