Skip to content

Instantly share code, notes, and snippets.

@Akira-Hayasaka
Created October 12, 2018 00:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akira-Hayasaka/e0a2d2da41c47acb4dbc5a991eb4b35b to your computer and use it in GitHub Desktop.
Save Akira-Hayasaka/e0a2d2da41c47acb4dbc5a991eb4b35b to your computer and use it in GitHub Desktop.
auto conv_utf8_to_sjis = [](string srcUTF8) -> string
{
int lenghtUnicode = MultiByteToWideChar(CP_UTF8, 0, srcUTF8.c_str(), srcUTF8.size() + 1, NULL, 0);
wchar_t* bufUnicode = new wchar_t[lenghtUnicode];
MultiByteToWideChar(CP_UTF8, 0, srcUTF8.c_str(), srcUTF8.size() + 1, bufUnicode, lenghtUnicode);
int lengthSJis = WideCharToMultiByte(CP_THREAD_ACP, 0, bufUnicode, -1, NULL, 0, NULL, NULL);
char* bufShiftJis = new char[lengthSJis];
WideCharToMultiByte(CP_THREAD_ACP, 0, bufUnicode, lenghtUnicode + 1, bufShiftJis, lengthSJis, NULL, NULL);
string strSJis(bufShiftJis);
delete bufUnicode;
delete bufShiftJis;
return strSJis;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment