Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- #include <wchar.h>
- #include <string.h>
- /* string consisting of several Asian characters */
- wchar_t wcsString[] = L"u9580u961cu9640u963fu963bu9644";
- int main()
- {
- size_t wcsChars = wcslen( wcsString);
- size_t sizeRequired = WideCharToMultiByte( 950, 0, wcsString, -1,
- NULL, 0, NULL, NULL);
- printf( "Wide chars in wcsString: %un", wcsChars);
- printf( "Bytes required for CP950 encoding (excluding NUL terminator): %un",
- sizeRequired-1);
- sizeRequired = WideCharToMultiByte( CP_UTF8, 0, wcsString, -1,
- NULL, 0, NULL, NULL);
- printf( "Bytes required for UTF8 encoding (excluding NUL terminator): %un",
- sizeRequired-1);
- }
- Wide chars in wcsString: 6
- Bytes required for CP950 encoding (excluding NUL terminator): 12
- Bytes required for UTF8 encoding (excluding NUL terminator): 18
- #include <string>
- std::string wstrtostr(const std::wstring &wstr)
- {
- // Convert a Unicode string to an ASCII string
- std::string strTo;
- char *szTo = new char[wstr.length() + 1];
- szTo[wstr.size()] = '