【问题标题】:How to specify the output format for Null node in yaml-cpp?如何在 yaml-cpp 中指定 Null 节点的输出格式?
【发布时间】:2013-12-12 12:54:44
【问题描述】:

我使用当前(2013/12/12)最新版本的 yaml-cpp。

我注意到YAML::Load("")YAML::Load("---\n...") 产生一个空节点, 即YAML::Load("").Type() == YAML::NodeType::Null 然而,当发送到std::ostream 时,前者输出一个空字符串 但后者输出波浪号 (~)。

我希望两个节点都输出一个空字符串。 我怎样才能实现它?

我想这样做是因为我注意到当我使用 YAML::Load 时,波浪号被解释为字符串。

这是显示这种差异的代码。

#include <yaml-cpp/yaml.h>
#include <iostream>
#include <cassert>

int main() {
    YAML::Node node1 = YAML::Load("");
    YAML::Node node2 = YAML::Load("---\n...");

    assert (node1.Type() == YAML::NodeType::Null);
    assert (node2.Type() == YAML::NodeType::Null);

    std::cout << node1 << std::endl;
    std::cout << node2 << std::endl;
}

/* OUTPUT:

~
*/

【问题讨论】:

  • 现在无法在 yaml-cpp 中完成。您能否在项目页面上提交错误报告?
  • @JesseBeder 我提交了issue 230

标签: yaml-cpp


【解决方案1】:

根据the Github Issue,此行为已在 2016 年修复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多