Is the C ++ 11 <codecvt> header available in the latest GCC?
After reading Is <codecvt> not a standard header? I'm not sure what to do, as my version of Windows for the codebase uses <codecvt> to convert between wide strings and strings. I am currently using GCC 4.7 for my Linux version of the code. Is <codecvt> missing in the latest GCC? What will be the workaround?
By the way, as indicated here , the following code will not work with GCC:
wstring ws = L"hello"; string ns(ws.begin(), ws.end()); How about using mbsrtowcs and wcsrtombs ? Although they come from C, it is not very convenient to use with std::string and std::wstring (but you can always create your own convenient C ++ functions based on them). In addition, the conversion is based on the current locale C. Thus, your code snippet can be changed to something like:
std::mbstate_t state = {}; const wchar_t* p = L"hello"; std::string ns(std::wcsrtombs(NULL, &p, 0, &state) + 1); std::wcsrtombs(&ns[0], &p, ns.size(), &state); ns.pop_back();