国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 課堂 > 技術開發 > 正文

Boost庫對unicode字符集的支持方式探究

2023-06-23 14:40:21
字體:
來源:轉載
供稿:網友

最近習使用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字符集

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乐清市| 长治市| 轮台县| 小金县| 屯昌县| 新河县| 黄浦区| 伊吾县| 灌阳县| 兴海县| 腾冲县| 讷河市| 四平市| 镇原县| 辽宁省| 南靖县| 台湾省| 贺州市| 鲜城| 界首市| 江口县| 广汉市| 军事| 萝北县| 榆中县| 岐山县| 安新县| 枞阳县| 贵溪市| 德惠市| 喀什市| 南召县| 洞口县| 上虞市| 界首市| 和田县| 花莲县| 连平县| 稷山县| 曲阳县| 五家渠市|