【发布时间】:2015-04-26 20:43:31
【问题描述】:
我已经使用 boost::spirit 实现了简单的 ascii 解析器。
目标 ascii 文件看起来像
n
0 23 45 10.0 0.5
.....
n-1 x y .....
但它在 measure_list 中只返回 1 个元素
如果我试图将 ASCII 读取为简单的 vector<double> 而不是结构化的,例如 - 它工作正常。怎么了?
struct measure
{
int id;
double x, y, size_, angle;
}
BOOST_FUSION_ADAPT_STRUCT(measure, (int, id)(double, x)(double, y)(double, size_)(double, angel))
typedef std::vector<measure> data_t;
void RelativeMeasure(string filename)
{
clear();
if(!filesystem::exists(filename)) return;
file_name = filename;
ifstream calibration_file(filename);
if(calibration_file.is_open())
{
int key_count;
calibration_file >> key_count;
istreambuf_iterator<char> eos;
istreambuf_iterator<char> it(calibration_file);
std::string strver(it, eos);
std::vector<measure> measure_list;
measure_list.reserve(100000);
qi::phrase_parse(strver.begin(), strver.end(), (qi::int_ > qi::double_ > qi::double_ > qi::double_ > qi::double_) % qi::eol, qi::blank, measure_list);
for each(auto measure in measure_list) key_list.push_back(KeyPoint(measure.x, measure.y, measure.size_, measure.angel));
}
【问题讨论】:
-
(double, angel))我想你的意思是说(double, angle)) -
请构造一个MCVE。很难(如果不是不可能的话)从即使完整也无法编译的伪代码中分辨出真实代码中可能被破坏的内容。它可能是任何东西,从格式错误的输入数据(空行?)到代码的另一部分中的未定义行为,都会弄乱解析器。
标签: c++ boost boost-spirit-qi