yaml-cpp

How to read a yaml node array into std::vector


A total noob with yaml-cpp. I have a node something like this:

numbers : [1,2,3,4,5]

In the CPP file, I want to parse into a vector:

std::vector<int> vi = node["numbers"];

This doesn't work. I can't find any documentation other than the tutorial- and it isn't covered in the tutoral.


Solution

  • yaml-cpp already has overloads for standard container types, so the as<T>() function works here:

    std::vector<int> vi = node["numbers"].as<std::vector<int>>();