69,373
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR szUtf16[100] = TEXT("Hello你好!");
char szGb2312[100];
SetConsoleOutputCP(936); // GB2312
_tprintf(TEXT("%s\n"), szUtf16);
_tprintf(TEXT("%ls\n"), szUtf16);
_tprintf(TEXT("%hs\n"), szUtf16);
_getch();
SetConsoleOutputCP(1200); // UTF-16
_tprintf(TEXT("%s\n"), szUtf16);
_tprintf(TEXT("%ls\n"), szUtf16);
_tprintf(TEXT("%hs\n"), szUtf16);
_getch();
SetConsoleOutputCP(936); // GB2312
WideCharToMultiByte(936, 0, szUtf16, -1, szGb2312, 100, 0, 0);
_tprintf(TEXT("%S\n"), szGb2312);
_getch();
return 0;
}
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
//Sets the locale to the default, which is the user-default ANSI code page obtained from the operating system.
setlocale( LC_ALL, "" );
TCHAR szUtf16[100] = TEXT("Hello你好!");
SetConsoleOutputCP(936); // GB2312
_tprintf(TEXT("%s\n"), szUtf16);
_tprintf(TEXT("%ls\n"), szUtf16);
_getch();
SetConsoleOutputCP(1200); // UTF-16
_tprintf(TEXT("%s\n"), szUtf16);
_tprintf(TEXT("%ls\n"), szUtf16);
_getch();
return 0;
}
#include <stdio.h>
#include <tchar.h>
#include <locale.h>
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL, "");
WCHAR szUtf16[] = L"Hello你好!";
wprintf(L"%s\n", szUtf16);
printf("%S\n", szUtf16);
TCHAR szT[] = _T("Hello你好!");
_tprintf(_T("%s\n"), szT);
getchar();
return 0;
}
#include <stdio.h>
#include <tchar.h>
#include <locale.h>
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL, "");
WCHAR szUtf16[] = L"Hello你好!";
wprintf(L"%s\n", szUtf16);
printf("%S\n", szUtf16);
getchar();
return 0;
}