Skip to content

Accessing fields by name #231

Answered by biojppm
jslezosky asked this question in Q&A
Mar 17, 2022 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

Your loop variable is already the command, so you are looking twice for IAU_BOOT_RST. That is, you are doing the equivalent to tree["commands"]["IAU_BOOT_RST"]["IAU_BOOT_RST"]["dmoab_extension"]["size"], and it fails.

What you want is simply this:

for (ryml::NodeRef const& cmd : tree["commands"].children())
  std::cout << cmd.key() << ": size=" << cmd["dmoab_extension"]["size"].val() << "\n";

As for the conversion, it's in the quickstart. In this case:

int size;
cmd["dmoab_extension"]["size"] >> size;

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@jslezosky
Comment options

@jslezosky
Comment options

@biojppm
Comment options

@jslezosky
Comment options

Answer selected by biojppm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants