簡體   English   中英

如何在yaml-cpp中發出帶有額外換行符的映射序列

[英]How to emit a sequence of mappings with extra newlines in yaml-cpp

我想以以下格式使用yaml-cpp庫發出一系列映射:

-
  name: <some_name>
  value: <some_value>

我正在使用此代碼:

Emitter out;
out << YAML::BeginSeq;

for (unsigned int i = 0; i < prof_info_.numOfSettings; ++i)
{
   str = NvUS_to_string(stgs[i].settingName);

   if (str != "")
   {
      out << YAML::BeginMap;

      out << YAML::Key << "name";
      out << YAML::Value << str;

      string d_str = get_value_name_from_value_id(stgs[i].settingId, (unsigned int)stgs[i].u32CurrentValue);

      out << YAML::Key << "value";
      out << YAML::Value << d_str;

      out << YAML::EndMap;
  }
}

out << YAML::EndSeq;

f_out << out.c_str();

我得到:

- name: <some_name>
  value: <some_value>

我嘗試添加

out << YAML::NewLine;

在地圖的開頭,但是給出了錯誤的結果。 如何獲得所需的輸出?

YAML::Newline 剛過 YAML::BeginMap獲得后換行-但地圖的第一項之前:

out << YAML::BeginMap;
out << YAML::Newline;

out << YAML::Key << "name";
out << YAML::Value << str;

out << YAML::Key << "value";
out << YAML::Value << d_str;

out << YAML::EndMap;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM