使用yaml-cpp 0.5.1的可选键

pac*_*_uk 5 c++ yaml-cpp

上一个答案描述了如何使用确定yaml节点中是否存在密钥YAML::Node::FindValue("parameter").

不幸的是,我不能在最新版本(0.5.1)中调用它:

 error: ‘class YAML::Node’ has no member named ‘FindValue’
Run Code Online (Sandbox Code Playgroud)

这是预期可行的还是有一个在最新版本中有效的等效功能?

Jes*_*der 9

在新的API中,您可以检查:

if (node["parameter"]) {
  // ...
}
Run Code Online (Sandbox Code Playgroud)

if (...)块中定义对象可能很方便:

if (YAML::Node parameter = node["parameter"]) {
  // process parameter
}
Run Code Online (Sandbox Code Playgroud)

  • 十分感谢.现在你已经拼出来了,我看到这是本教程的第一步.哎呀. (2认同)