I need crossplatform code to skip leading spaces for wide string. It's looking that g++ (and Qt obviously) doesn't initialize slots for wide string at all So following code works fine for VC++ but almost g++ fails with bad_cast exception:
#include <string>
#include <locale>
#include <iostream>
int main()
{
typedef std::ctype<std::wstring::value_type> vtct;
std::wstring str=L" 1122";
const std::wstring::value_type* unspace =
std::use_facet<vtct>( std::locale::classic() ).
scan_not(std::ctype_base::space|std::ctype_base::punct,
str.c_str(), str.c_str() + str.length());
//std::cout << unspace << std::endl;
wprintf(L"{%s}\n", unspace);
return 0;
}
According to spec: *"bad_cast exception when the facet repository in the locale object contains no facet with the requested locale::id"*
So general question how g++ deals with wide string? More narrow question - how to initialize facets at least for ctype?
Update: after some experiments, I've detected that linux g++ correctly initializes facet for wide string - so code works. Obviously described problem is feature if mingw only.