如何打印出 yaml::Node?

发布于 2025-01-19 16:38:07 字数 350 浏览 1 评论 0原文

我尝试了许多不同的方法来做到这一点。我有一堆彼此嵌套的节点:

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

我只想将A打印到字符串上,这样我就可以看到YAML的样子。我已经尝试了以下操作:

a.as<std::string>()

以及

std:: string str;
a >> str;

第一个抛出异常,而第二个则没有编译。

我想念什么?感觉这应该非常容易。

I have tried many different ways to do this. I have a bunch of nodes nested under each other e.g:

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. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

全部不再 2025-01-26 16:38:07

使用转储功能。 IE

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

std::string yaml_string = YAML::Dump(a);

Use the Dump function. i.e.

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

std::string yaml_string = YAML::Dump(a);
×纯※雪 2025-01-26 16:38:07

您可以使用发射器打印节点

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

You can print Node using Emitter

Emitter emitter;
emitter << node;
std::cout<<"Node :" <<emitter.c_str()<<std::endl;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文