0

I know little about yaml then I use word yaml section to describe something like this below:

---
- section 1:
    subsection: 1
    subsection: 2

- section 2:
    subsection: 1
    subsection: 2

my code is not complete but this what I wrote:

class YParser{
        public:
                YAML::Node conf;
                const YAML::Node& section1;
                const YAML::Node& section2;

                void init(std::string address) {

                        conf   = YAML::LoadFile(address);
                        section1  = conf["section1"];
                        section2  = conf["section2"];
                }

                void show(std::string something){

                        if(!conf[something])
                                return ;
                        std::cout << something <<" : " << conf[something].as<std::string>() << std::endl;
                }
};

What I want is to have access to read data from a section and it's subsections.

Amir reza Riahi
  • 1,540
  • 2
  • 8
  • 34
  • The document you pasted is an array of two objects, each with one key (`section 1` and `section 2` respectively. I don't know yaml-cpp, but you should probably use `conf[0]` and `conf[1]`. – Botje Oct 29 '20 at 23:53
  • you want to use `section 1 : ` instead of `section : 1` ? – ignacio Oct 30 '20 at 00:12
  • [this](https://stackoverflow.com/questions/31368135/yaml-cpp-read-sequence-in-item) may help – ignacio Oct 30 '20 at 00:12

0 Answers0