【问题标题】:how can I print a 2d list with the 2 minus symbols on the same line with yaml cpp?如何使用 yaml cpp 在同一行打印带有 2 个减号的 2d 列表?
【发布时间】:2020-04-08 09:39:30
【问题描述】:

我想使用 yaml-cpp 创建以下 Yaml:

  steps:
    - - name: flip-coin
        template: flip-coin
    - - name: heads
        template: heads
        when: "{{steps.flip-coin.outputs.result}} == heads"
      - name: tails
        template: tails
        when: "{{steps.flip-coin.outputs.result}} == tails"

但我不能在同一行打印减号。这就是我得到的:

  steps:
    -
      - name: flip-coin
        template: flip-coin
    -
      - name: heads
        template: heads
        when: "{{steps.flip-coin.outputs.result}} == heads"
      - name: tails
        template: tails
        when: "{{steps.flip-coin.outputs.result}} == tails"

我的代码是

    YAML::Node node;
    node["steps"][0][0]["name"]="flip-coin";
    node["steps"][0][0]["template"]="flip-coin";

    node["steps"][1][0]["name"]="heads";
    node["steps"][1][0]["template"]="heads";
    node["steps"][1][0]["when"]="{{steps.flip-coin.outputs.result}} == heads";

    node["steps"][1][1]["name"]="tails";
    node["steps"][1][1]["template"]="tails";
    node["steps"][1][1]["when"]="{{steps.flip-coin.outputs.result}} == tails";

    YAML::Emitter out;
    out << node;
    std::cout << out.c_str();

【问题讨论】:

    标签: c++ yaml yaml-cpp


    【解决方案1】:

    existing manipulators 不包含任何可以让您配置紧凑内联序列表示法的内容,所以我很确定这是不可能的。

    通常,YAML 并非旨在逐个字符地微调输出的外观。另见this related question。间距信息是一个演示细节,不会出现在您的数据中。因此,您的数据以实现认为合适的方式呈现,除了可用的操纵器之外,您无能为力。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-20
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2018-05-12
      • 1970-01-01
      相关资源
      最近更新 更多