C++ 如何使用yaml cpp获取序列名

C++ 如何使用yaml cpp获取序列名,c++,yaml-cpp,C++,Yaml Cpp,关于这个问题 如果yaml看起来像 sensors: - id1: hardwareId: 28-000005a32133 type: 1 - id2: hardwareId: 28-000005a32132 type: 4 如何从节点获取序列的名称? 使用传感器节点如何获取id1和id2的名称?只需迭代节点即可;您将获得键/值对: for (const auto& kv : node["sensors"]) { kv.fir

关于这个问题

如果yaml看起来像

sensors:
  - id1:
      hardwareId: 28-000005a32133
      type: 1
  - id2:
      hardwareId: 28-000005a32132
      type: 4
如何从节点获取序列的名称?
使用传感器节点如何获取id1和id2的名称?

只需迭代节点即可;您将获得键/值对:

for (const auto& kv : node["sensors"]) {
  kv.first.as<std::string>();  // "id1" or "id2"
}
for(const auto&kv:node[“sensors”]){
kv.first.as();/“id1”或“id2”
}