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

作者:朱金灿
来源:http://blog.csdn.net/clever101


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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值