c++ - Boost Spirit Qi - 使用基于流的解析复制最后一个字母

标签 c++ boost boost-spirit libc++

这可能很明显,但是为什么 boost 中基于流的解析会重复最后一个字母呢?我一定是做错了什么:

#include <iostream>
#include <sstream>

#include <boost/spirit/include/qi.hpp>

namespace qi = boost::spirit::qi;

int main() {
    std::string input = "hello";
    std::stringstream ss(input);

    std::string r1, r2;
    boost::spirit::istream_iterator first(ss), last;

    qi::phrase_parse(input.begin(), input.end(), qi::lexeme[qi::alpha >> *qi::alnum], qi::space, r1);

    std::cout << r1 << std::endl; // prints "hello"

    qi::phrase_parse(first, last, qi::lexeme[qi::alpha >> *qi::alnum], qi::space, r2);

    std::cout << r2 << std::endl; // prints "helloo"
}

使用 XCode 5.0 和 Boost 1.54.0 测试。

编辑: 该问题似乎特定于 libc++。有人用 Clang care 来确认吗?

最佳答案

如果我理解正确的话,you're not supposed to use input iterators ,因为它们会给回溯带来问题。也许这只是纯粹的运气/实现上的不同,这有时完全有效。

关于c++ - Boost Spirit Qi - 使用基于流的解析复制最后一个字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19401248/

相关文章:

python - ld : library not found for -lboost_python on MacOS

c++ - 是否有可能有一个继承最终函数但创建相同函数(而不是重写)的派生类?

c++ - 作用域但 "semi-weakly"类型枚举

c++ - SO_RCVTIME和SO_RCVTIMEO不影响Boost.Asio操作

c++ - Boost C++ - 搜索 spirit 符号表

c++ - boost 路径指向的目录中文件的路径

c++ - 将多个值插入 vector

c++ - 将 setw 与用户定义的 ostream 运算符一起使用

c++ - Boost Spirit 2 - 符号扩展和回溯

c++ - Spirit Qi MiniC 示例的语法树空节点问题