首 页IT知识库翔宇问吧收藏本站
当前位置:翔宇亭IT乐园IT知识库编程技术编程综合

Boost库对unicode字符集的支持方式探究

减小字体 增大字体 作者:朱金灿  来源:http://blog.csdn.net/clever101  发布时间:2010-10-16 08:32:37

最近习使用Boost库,发现Boost库对unicode字符集的支持好像采用和STL类似的方式(当然没有完全证实)。STL是什么方式呢?就是在原有的ANSI类型上加上w表示这是unicode类型,如std::string对应std::wstring,std::cout对应std::wcout。Boost库也是采用这种方式,据我已经测试有:

字符串格式化:boost::format对应boost::wformat

文件系统路径:boost::filesystem::path对应boost::filesystem::wpath

下面是一个测试程序:

 

 

  1. #include <stdlib.h>   
  2. #include <iostream>   
  3. using std::cout;   
  4. using std::wcout;   
  5. using std::endl;    
  6. #include <string>   
  7. using std::string;   
  8. using std::wstring;   
  9. #include "boost/algorithm/string.hpp"   
  10. #include "boost/filesystem/path.hpp"   
  11. #include "boost/filesystem/operations.hpp"   
  12. #include "boost/format.hpp"   
  13. int main(int argc, char* argv[])   
  14. {   
  15.     // ANSI字符的格式化   
  16.     cout << boost::format( "%1% %2%" ) % "Hell" % "Low" <<endl;    
  17.     string s1 = boost::str( boost::format( "%2% %1%" ) % "Hell" % "Low" );   
  18.     cout << s1 << endl;    
  19.     // UNICODE字符的格式化   
  20.     wcout << boost::wformat( L"%s %X" ) % L"-1 is" % -1 << endl;    
  21.     wstring s2 = boost::str( boost::wformat( L"%2$s %1$.2f" ) % 3.141592 % L"Version" );   
  22.     wcout << s2 << endl;    
  23.     // 获取应用程序所在目录(ANSI字符),注意是boost::filesystem::path   
  24.     string AnsiPath = boost::filesystem::initial_path<boost::filesystem::path>().string();   
  25.     cout<<AnsiPath<<endl;   
  26.     // 获取应用程序所在目录(UNICODE字符),注意是boost::filesystem::wpath   
  27.     wstring UnicodePath = boost::filesystem::initial_path<boost::filesystem::wpath>().string();   
  28.     wcout<<UnicodePath<<endl;   
  29.     system("PAUSE");   
  30.     return 0;   
  31. }   

编译环境是:WinXp + sp3,VS 2008 + sp1,unicode字符集

原文地址:http://blog.csdn.net/clever101/archive/2010/08/31/5854287.aspx


本文源自:翔宇亭——IT乐园(http://www.biye5u.com),转载请保留此信息!

知识评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 1分

内 容:

            请注意用语文明且合法,不要发布带有攻击性、侮辱性的言论,谢谢合作!

         通知管理员 验证码:

关于本站 | 网站帮助 | 广告合作 | 网站声明 | 友情连接 | 网站地图 | 用户守则 | 联系我们 |
本站大多数内容来自互联网或网站会员发布,如有侵权,请来信告之,谢谢!
Copyright © 2007-2017 biye5u.com. All Rights Reserved.
网站备案号:黑ICP备13005378号-3