我刚刚开始使用yaml-cpp,我设法正确地构建了它,并运行了yaml-cpp wiki中的一些示例,但我找不到一种方法将发射器保存到文件中。
这是不可能的吗?我的意思是PyYAML库有一个“转储”功能。yaml-cpp中没有这样的功能吗?是否可以将yaml发射器转换为stl流,然后将其转储到yaml文件?
请让我知道
谢谢,亚当
发布于 2010-07-28 04:52:49
函数Emitter::c_str()返回一个NULL-terminated C样式字符串(您不必释放该字符串),然后可以将其写入文件。例如:
YAML::Emitter emitter;
emitter << "Hello world!";
std::ofstream fout("file.yaml");
fout << emitter.c_str();还有Emitter::size(),它返回该字符串中的字节数,以防您想要执行更高级的操作,而不想遍历字符串来查找其长度。
如果你只想把一个Node转储到一个流中,有一个快捷方式:
YAML::Node node = ...;
std::ofstream fout("file.yaml");
fout << node;https://stackoverflow.com/questions/3342355
复制相似问题