简体   繁体   English

如何打印出 yaml::Node?

[英]How to print out a yaml::Node?

I have tried many different ways to do this.我尝试了许多不同的方法来做到这一点。 I have a bunch of nodes nested under each other eg:我有一堆节点相互嵌套,例如:

yaml::Node a;
a["foo"] = 3;
yaml::Node b;
b["baz"] = 7;
a["bar"] = b;

I just want to print a to a string so I can see what the yaml looks like.我只想将 a 打印到一个字符串中,这样我就可以看到 yaml 是什么样子的。 I've tried the following:我试过以下方法:

a.as<std::string>()

as well as

std:: string str;
a >> str;

The first throws an exception while the second doesn't compile.第一个抛出异常,而第二个不编译。

What am I missing?我错过了什么? This feels like it should be very easy.这个感觉应该是很容易的。

You can print Node using Emitter您可以使用Emitter打印节点

Emitter emitter;
emitter << node;
std::cout<<"Node :" <<emitter.c_str()<<std::endl;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM