C/C++ 输出宽字符 printf + %ls or wcout

来源:互联网 发布:蓝鸽集团知乎 编辑:程序博客网 时间:2024/05/23 12:25

在C/C++中输出宽字符可以使用printf + %ls 或者 wcout,详细请看代码:

[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
  1. // 【MoreWindows工作笔记1】 C/C++ 输出宽字符 printf + %ls or wcout  
  2. #include <Windows.h>  
  3. #include <stdio.h>  
  4. #include <iostream>  
  5. using namespace std;  
  6. int main()  
  7. {  
  8.   printf("    【MoreWindows工作笔记1】 C/C++ 输出宽字符 printf + %ls or wcout\n");      
  9.   printf(" - http://blog.csdn.net/morewindows/article/details/16358175 -\n");      
  10.   printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n");    
  11.   
  12.   char text[] = "MoreWindows";  
  13.   WCHAR w_text[] = L"http://blog.csdn.net/MoreWindows";  
  14.   
  15.   printf("%s %ls\n", text, w_text);  
  16.   
  17.   cout<<text<<" ";  
  18.   wcout<<w_text<<endl;  
  19.   return 0;  
  20. }  

运行结果如下:

另外,wprintf + %s也可以输出宽字符。

0 0
原创粉丝点击