【发布时间】:2012-05-12 09:43:17
【问题描述】:
我正在努力学习boost::spirit。例如,我试图将一系列单词解析为vector<string>。我试过这个:
#include <boost/spirit/include/qi.hpp>
#include <boost/foreach.hpp>
namespace qi = boost::spirit::qi;
int main() {
std::vector<std::string> words;
std::string input = "this is a test";
bool result = qi::phrase_parse(
input.begin(), input.end(),
+(+qi::char_),
qi::space,
words);
BOOST_FOREACH(std::string str, words) {
std::cout << "'" << str << "'" << std::endl;
}
}
这给了我这个输出:
'thisisatest'
但我想要以下输出,其中每个单词都单独匹配:
'this'
'is'
'a'
'test'
如果可能,我想避免为这个简单的案例定义我自己的 qi::grammar 子类。
【问题讨论】:
标签: c++ parsing boost boost-spirit boost-spirit-qi