#include #include #include int main() { // UTF-8 string const char* utf8Hostname = "ドメイン名.com"; // Buffer for UTF-16 string wchar_t utf16Hostname[256]; // Convert UTF-8 to UTF-16 if (mbstowcs(utf16Hostname, utf8Hostname, sizeof(utf16Hostname) / sizeof(utf16Hostname[0])) != (size_t)-1) { // Display UTF-16 string wprintf(L"UTF-16 string: %s\n", utf16Hostname); // Now let's decode UTF-16 back to UTF-8 char decodedUtf8[256]; size_t len; if (wcstombs_s(&len, decodedUtf8, sizeof(decodedUtf8), utf16Hostname, _TRUNCATE) == 0) { // Display the decoded UTF-8 string printf("Decoded UTF-8 string: %s\n", decodedUtf8); } else { // Handle decoding error perror("Error converting UTF-16 to UTF-8"); } } else { // Handle encoding error perror("Error converting UTF-8 to UTF-16"); } return 0; }