I want to use yaml-cpp for a project of mine to generate a yaml-file however I have trouble figuring out how exactly I have to go about this. The yaml file I need to emit should look like this:
action_counts:
version: 0.3
subtree:
- name: system
local:
- name: adder
action_counts:
- name: add
counts: 1000
- name: idle
counts: 10000
So far I haven't been able to write the last four lines. I know that a '-' represents an array but I don't know how I can print the name and counts keys like that.
I have written some bits of code to experiment with yaml-cpp. The code looked like this:
YAML::Node node;
node["action_counts"] = YAML::Null;
node["action_counts"]["version"] = "0.3";
node["action_counts"]["subtree"].push_back("system");
std::ofstream fout("fileUpdate.yaml");
fout << node;
return 0;
And the output it produces is this:
action_counts:
version: 0.3
subtree:
- system
The last line here is wrong but I haven't managed to find out how to print - name: system
instead of this. How do I do this?
Once thats done how do I print the rest? Is local
a part of the - name
array? I think once I know how to format those to two lines I can figure out the rest by myself.