让boost property_tree支持中文路径
2016-04-07 10:13
323 查看
让boost property_tree支持中文路径
分析总结:
boost内部实际上用的是STL的串流 ,有时候用ifstream或ofstream打开带有中文路径的文件会失败。
解决办法:
1、使用C语言的函数设置为中文运行环境
setlocale(LC_ALL,"Chinese-simplified");
2、使用STL函数设置为系统语言环境
std::locale::global(std::locale(""));
#include <cstdlib> #include <stdio.h> #include <iostream> #include <string> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ini_parser.hpp> using namespace std; int main(int argc, char** argv) { string ini_file = "C:/工程1/test4.ini"; std::locale::global(std::locale("")); //添加这句,可以让ini_file中包含中文字符,如果没有这句,会抛出异常,can not open file using boost::property_tree::ptree; ptree pt; pt.put("data.SourceImgPath", "a"); pt.put("data.MaskImgPath", "b"); pt.put("data.MarkedImgPath", "c"); boost::property_tree::ini_parser::write_ini(ini_file, pt); return 0; }
分析总结:
boost内部实际上用的是STL的串流 ,有时候用ifstream或ofstream打开带有中文路径的文件会失败。
解决办法:
1、使用C语言的函数设置为中文运行环境
setlocale(LC_ALL,"Chinese-simplified");
2、使用STL函数设置为系统语言环境
std::locale::global(std::locale(""));
相关文章推荐
- boost相关小知识(长期顶置更新)
- C++单元测试:boost.test
- boost asio学习笔记 [1] - 同步通讯
- boost_asio学习笔记[2] - 客户端异步通讯
- boost::flat_map性能测试
- Ubuntu下如何安装boost?
- How to get a boost::shared_ptr from this
- boost 库 enable_shared_from_this 实现原理分析
- boost bind使用指南
- 使用boost进行CRC64计算
- [网络开发]boost::asio简介
- Windows下如何编译使用boost?
- Boost库学习(0)
- Boost库学习(1)log和unittest
- Boost库学习(2)thread 1
- Boost库学习(3)thread 2
- Boost库学习(4)thread 3
- Boost库学习(6)filesystem
- Boost库学习(7)regex
- Boost库学习(8)log