1

私はブーストスピリット2に入ろうとしていますが、次のコードは期待どおりに機能しません。

template<typename Iterator>
struct my_grammar : qi::grammar<Iterator, std::string()>
{
    my_grammar() : my_grammar::base_type(time_literal)
    {
        using ascii::char_;
        using ascii::digit;

        time_literal = digit >> -digit >> char_(':') >> digit >> digit >> -(char_(':') >> digit >> digit);
    }

    qi::rule<Iterator, std::string()> time_literal;
};

void main()
{
    my_grammar<std::string::iterator> g;
    std::string input("01:02:03");
    std::string::iterator begin = input.begin();
    std::string::iterator iter = begin;
    std::string::iterator end = input.end();
    std::string result;
    bool matched = phrase_parse(iter, end, g, ascii::space, result);
    std::cout << (matched ? "matched "+std::string(begin, iter) : "no match") << std::endl;
    if (iter != end)
        std::cout << "remaining: " << std::string(iter, end) << std::endl;
    else
        std::cout << "result: " << result << std::endl;
    std::cout << std::endl;
}

これは印刷します:

matched: 01:02:03
result: 01:02:

しかし、私は見ることを期待していました:

matched: 01:02:03
result: 01:02:03

では、これらの最後の2桁はどこに行き、どうすれば元に戻すことができますか?

4

0 に答える 0