Yaml-cpp 似乎在我的地图条目之前插入了一个问号。这是结果:
baryons:
nucleons:
- proton:
quarkContent: [u, u, d]
charge: 1
- antiproton:
quarkContent: [au, au, ad]
charge: -1
- neutron:
quarkContent: [d, d, u]
charge: 0
- antineutron:
quarkContent: [ad, ad, au]
charge: 0
? hyperons:
- lambda:
quarkContent: [u, d, s]
charge: 0
- antilambda:
quarkContent: [au, ad, as]
charge: 0
如您所见,从超子开始,有一个问号。我尝试添加更多条目以查看会发生什么。它似乎在?
和之间交替:
。这很奇怪。
我尝试删除核子键和超子键的所有内容,我仍然得到这个
baryons:
nucleons:
- Hello
? hyperons:
- Hello
嗯。确实很奇怪。这是我的代码。原谅凌乱
#include "yaml-cpp/yaml.h"
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
#include <typeinfo>
using namespace YAML;
void addParticle(Emitter * e, std::string name, std::string qc1, std::string qc2, std::string qc3, int charge){
*e << BeginMap << Key << name;
*e << Value;
*e << BeginMap;
*e << Key << "quarkContent" << Value << Flow << BeginSeq << qc1 << qc2 << qc3 << EndSeq;
*e << Key << "charge" << Value << charge;
*e << EndMap;
*e << EndMap;
*e << BeginMap << Key << "anti" + name;
*e << Value;
*e << BeginMap;
*e << Key << "quarkContent" << Value << Flow << BeginSeq << "a" + qc1 << "a" + qc2 << "a" + qc3 << EndSeq;
*e << Key << "charge" << Value << charge * -1;
*e << EndMap;
*e << EndMap;
};
int main(){
Emitter e;
e << BeginMap;
e << Key << "baryons";
e << Value;
e << BeginMap;
e << Key << "nucleons";
e << Value;
e << BeginSeq;
addParticle(&e, "proton", "u", "u", "d", 1);
addParticle(&e, "neutron", "d", "d", "u", 0);
e << EndSeq;
e << EndMap;
e << BeginMap;
e << Key << "hyperons";
e << Value;
e << BeginSeq;
addParticle(&e, "lambda", "u", "d", "s", 0);
e << EndSeq;
e << EndMap;
e << EndMap;
std::ofstream particlesYAML;
particlesYAML.open("particles.yml");
particlesYAML.write(e.c_str(), strlen(e.c_str()));
particlesYAML.close();
return 0;
};
在旁注中,我正在缩进以减少混乱。所以也原谅。
另外,我的 YAML 结构好吗?还是我应该修改一些不同的东西?谢谢。