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

在看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" .

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