2013-07-09 44 views
1

我想用YAML-CPP库按以下格式发出的映射关系的映射seqence在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; 

在地图的开头,但它给出了错误的结果。我怎样才能得到我想要的输出?

+0

你想要的格式无效YAML。 –

+0

为什么? [http://www.yaml.org/](http://www.yaml.org/spec/1.2/spec.html#id2759963) – toodef

+0

yaml中的缩进问题。你想让它看起来像你的链接中的例子2.4吗? –

回答

1

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;