我有一个类(包含一些标量值和一个浮点向量),我想读取和写入一个实例作为另一个映射的值。
// 写 out << YAML::Key << "my_queue" << YAML::Value << my_queue; // 读取(其他代码被删掉...) for (YAML::Iterator it=doc.begin();it!=doc.end();++it) { std::string 键、值; it.first() >> 键; it.second() >> 值; if (key.compare("my_queue") == 0) { *它>>我的队列; } }
编写这门课效果很好,但无论我做什么,我似乎都无法阅读它。它不断抛出一个 InvalidScalar。
捕获 YAML::InvalidScalar yaml-cpp: 第 20 行第 13 列错误:无效标量
这就是输出(用 yaml-cpp 编写而没有报告任何错误)看起来像:
其他号码:80 我的队列: 尺寸:20 数据: - 3.5 - -1 - -1.5 - 0.25 - -24.75 - -5.75 - 2.75 - -33.55 - 7.25 - -11 - 15 - 37.5 - -3.75 - -28.25 - 18.5 - 14.25 - -36.5 - 6.75 - -0.75 - 14 最大尺寸:20 平均值:-0.0355586 标准开发:34.8981 even_more_data:1277150400
文档似乎说这是支持的用法,嵌套映射,在这种情况下,序列作为值之一。它抱怨它是一个 InvalidScalar,尽管我做的第一件事告诉它这是一张地图:
YAML::Emitter& 运算符 << ( YAML::Emitter& out, const MeanStd& w ) { 出 << YAML::BeginMap; out << YAML::Key << "大小"; 出 << YAML::Value << w.size(); out << YAML::Key << "数据"; 出 << YAML::Value << YAML::BeginSeq; for(Noor::Number i=0; i<w.size(); ++i) { 出 << w[i]; } 出 << YAML::EndSeq; out << YAML::Key << "max_size"; out << YAML::Value << w.get_max_size(); out << YAML::Key << "意思"; out << YAML::Value << w.mean(); out << YAML::Key << "stdev"; out << YAML::Value << w.stdev(); 出 << YAML::EndMap; 退出; }
有没有人看到这个问题?