如何在 Boost Spirit X3 中进行"stream"解析?
How to do "stream" parsing in Boost Spirit X3?
我正试图找到使用x3从istream
解析的正确方法。旧的文档指的是multi_pass
的东西,我还能用这个吗?或者有没有其他方法可以缓冲X3的流,以便它可以回溯?
您仍然可以使用它。只包括
#include <boost/spirit/include/support_istream_iterator.hpp>
示例在Coliru上直播
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/include/support_istream_iterator.hpp>
#include <iostream>
#include <sstream>
int main() {
std::istringstream iss("{ 123, 234, 345, 456, 567, 678, 789, 900, 1011 }");
boost::spirit::istream_iterator f(iss), l;
std::vector<int> values;
namespace x3 = boost::spirit::x3;
if (x3::phrase_parse(f, l, '{' >> (x3::int_ % ',') >> '}', x3::space, values)) {
std::cout << "Parse results:n";
for (auto v : values) std::cout << v << " ";
} else
std::cout << "Parse failedn";
}
打印
Parse results:
123 234 345 456 567 678 789 900 1011
相关文章:
- 继承函数的重载解析
- 基类中的函数名称解析
- 提升精神:解析布尔表达式并简化为规范范式
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- gcc和c++17的过载解析失败
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 构造函数和转换运算符之间的重载解析
- 未解析的外部符号_MsiLocateComponentW@12.
- '尝试解析可变参数模板时无法推断出'T的模板参数
- 为什么stream::忽略未按预期工作
- 非类型指针和引用模板参数,以及在编译时如何/为什么解析它们.c++
- C++的解析器在可以区分比较和模板实例化之前会做什么?
- 如何在 cpp 中解析此文件?
- 在C++中使用 gRPC 时未解析的外部符号
- IDE (CLion) 无法解析C++模板类型
- 配置文件解析器仅返回以前的值
- 增强精神解析器规则以检测语句中的特殊结尾
- 将向量解析<string>为字符串
- 如何在 Boost Spirit X3 中进行"stream"解析?
- String Stream in C++ 解析单词和数字字符串