您的位置:首页 > 其它

windows下快速转换unicode与ansi

2014-04-18 11:02 489 查看
不想使用WideCharToMultiByte和MultiByteToWideChar这两个API对ansi与unicode字符串进行转换

还好发现有%S(s为大写)

     ANSI    -----> UNICODE

    swprintf_s(UnicodeStr, SizeOfUnicodeStr, L"%S", AnsiStr) ;

UNICODE -----> ANSI

    sprintf_s(AnsiStr, SizeofAnsiStr, L"%S", UnicodeStr) ;

 

_tsetlocale(LC_ALL, TEXT("chs")) ;

char ansi[] = "你好 世界" ;
wchar_t unicode[100] ;
swprintf_s(unicode, 100, L"%S", ansi) ;
std::wcout << unicode << std::endl ;
//
wchar_t unicode1[] = L"你好 世界" ;
char ansi1[100] ;
sprintf_s(ansi1, 100, "%S", unicode1) ;
std::cout << ansi1 << std::endl ;

system("pause") ;


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: