Jason
Jason

Reputation: 63

yaml-cpp parsing strings

Is it possible to parse YAML formatted strings with yaml-cpp?

There isn't a YAML::Parser::Parser(std::string&) constructor. (I'm getting a YAML string via libcurl from a http-server.)

Upvotes: 6

Views: 4787

Answers (2)

Frank
Frank

Reputation: 66194

In the new version, you can parse a string directly (see here):

YAML::Node node = YAML::Load("[1, 2, 3]");

Upvotes: 9

Josh Kelley
Josh Kelley

Reputation: 58372

Try using a stringstream:

std::string s = "name: YAML from libcurl";
std::stringstream ss(s);
YAML::Parser parser(ss);

Upvotes: 9

Related Questions