2013-07-09 42 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;