Doesn't the codecvt
template take the state type as a parameter? Can you just use a pointer type there instead? I can't remember whether the various classes that use a codecvt
place requirements on the state type.
Assuming that you can't just change the state type... on MSVC 2008, mbstate_t
is typedef
d as an int
. The standard only requires that int
be larger than 16 bits and no larger than a long, so it's not 64-bit safe. I guess you would need to store an index or key into some data structure instead of a pointer.
update:
The following compiles under VS2008, at least:
std::wstring const in = L"input";
size_t const buf_size = 256;
char* buf = new char[buf_size];
wchar_t const* char_next;
char * byte_next;
void* state = NULL;
typedef std::codecvt<wchar_t, char, void*> codecvt_t;
codecvt_t::result res =
std::use_facet<codecvt_t>(std::locale()).out(
state, in.c_str(), in.c_str() + in.length(),
char_next, &buf[0], &buf[buf_size], byte_next);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…