码迷,mamicode.com
首页 > 其他好文 > 详细

使用 sprintf swprintf 函数进行 unicode 与 ANSI 编码的转换

时间:2015-04-16 12:13:07      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

在看Windows核心编程时 发现一个Unicode与Ascii编码转换比较方便的函数 就是使用sprintf和swprintf.

 1 char strA[100];
 2 wchar_t strW[100];
 3 
 4 //普通的sprintf  转换前后都是ANSI
 5 sprintf(strA, "%s", "ANSI Str");
 6 
 7 //将Unicode字符转换成ASCII
 8 sprintf(strA, "%S", L"Unicode Str");
 9 
10 //普通的swprintf 转换前后都是Unicode
11 sprintf(strW, L"%s", L"Unicode Str");
12 
13 //将ANSI转换为Unicode
14 sprintf(strW, L"%S", "ANSI Str");

上面需要了解的就是 如果需要两种不同的字符间转换 则需要使用大写的格式话符号 "%S" .

使用 sprintf swprintf 函数进行 unicode 与 ANSI 编码的转换

标签:

原文地址:http://www.cnblogs.com/uurun/p/4431292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!