Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

yaml-cpp

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.

like image 342
user2155055 Avatar asked Jan 13 '16 02:01

user2155055


1 Answers

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>>();
like image 141
Jesse Beder Avatar answered Oct 20 '22 14:10

Jesse Beder