![](/img/trans.png)
[英]boost::property_tree::json_parser::read_json cannot read files if path contains cyrillic characters
[英]boost property_tree::json_parser::read_json & iostreams::filtering_streambuf
我试图阅读放气的json并遇到类型转换问题,这里是代码
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
std::istringstream iss(std::ios::binary);
iss.rdbuf()->pubsetbuf(buf, len);
iss.imbue( std::locale("ru_RU.CP1251") );
in.push( boost::iostreams::zlib_decompressor() );
in.push( iss );
boost::property_tree::ptree pt;
boost::property_tree::json_parser::read_json(in, pt); // <-- Compile error
编译说:
src / ABPacking.cpp:48:错误:没有匹配函数来调用'read_json(boost :: iostreams :: filtering_streambuf,std :: allocator,boost :: iostreams :: public _>&,boost :: property_tree :: ptree&) “
问题是如何在不进行不必要的数据复制的情况下将filtering_streambuf传递给read_json ?
read_json
需要文件名或具有JSON内容的流 。 您正在尝试传递流缓冲区 ,它不知道如何处理它。
作为解决方案,只需将流缓冲区传递给使用它的istream
并将其传递给read_json
:
std::istream input(&in_buf);
read_json(input, pt);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.