如何使用 yaml-cpp 0.5.0 API 从列表中删除元素

How to remove an element from list using the yaml-cpp 0.5.0 API

本文关键字:列表 删除 元素 API 何使用 yaml-cpp      更新时间:2023-10-16

以下测试代码不会按预期从列表中删除元素:

YAML::Node node = YAML::Load("[1,2,3]");
node.remove(1); // expect that this should remove the middle element from the list
ofstream ofs("test.yml");
ofs << node;
ofs.close();

测试输出文件包含:

-1
-2
-3

该文件似乎包含原始列表中的值,并且未删除该元素。从列表中删除元素的正确方法是什么?

现在没有办法做到这一点(我没有想到这个!我已经提交了一个错误(http://code.google.com/p/yaml-cpp/issues/detail?id=190),但我不确定语法应该是什么。如果您有建议,请对该问题发表评论!