- ·上一篇文章:基于Mongodb分布式存储物理文件
- ·下一篇文章:为什么要学习OOP
Boost库对unicode字符集的支持方式探究
: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
下面是一个测试程序:
- #include <stdlib.h>
- #include <iostream>
- using std::cout;
- using std::wcout;
- using std::endl;
- #include <string>
- using std::string;
- using std::wstring;
- #include "boost/algorithm/string.hpp"
- #include "boost/filesystem/path.hpp"
- #include "boost/filesystem/operations.hpp"
- #include "boost/format.hpp"
- int main(int argc, char* argv[])
- {
- // ANSI字符的格式化
- cout << boost::format( "%1% %2%" ) % "Hell" % "Low" <<endl;
- string s1 = boost::str( boost::format( "%2% %1%" ) % "Hell" % "Low" );
- cout << s1 << endl;
- // UNICODE字符的格式化
- wcout << boost::wformat( L"%s %X" ) % L"-1 is" % -1 << endl;
- wstring s2 = boost::str( boost::wformat( L"%2$s %1$.2f" ) % 3.141592 % L"Version" );
- wcout << s2 << endl;
- // 获取应用程序所在目录(ANSI字符),注意是boost::filesystem::path
- string AnsiPath = boost::filesystem::initial_path<boost::filesystem::path>().string();
- cout<<AnsiPath<<endl;
- // 获取应用程序所在目录(UNICODE字符),注意是boost::filesystem::wpath
- wstring UnicodePath = boost::filesystem::initial_path<boost::filesystem::wpath>().string();
- wcout<<UnicodePath<<endl;
- system("PAUSE");
- return 0;
- }
编译环境是:WinXp + sp3,VS 2008 + sp1,unicode字符集
原文地址:http://blog.csdn.net/clever101/archive/2010/08/31/5854287.aspx
!
Boost库对unicode字符集的支持方式探究