我制作了简单的示例代码,通过引用yaml-cpp教程来演示YAML加载/转储与yaml-cpp(ver0.5.2)。转储结果文件不是我所期望的。
# config.yaml file
lastLogin: 1441030476
password: "pass1234"
username: "admin"#include <iostream>
#include <fstream>
#include <string>
#include <time.h>
#include "yaml-cpp/yaml.h"
int main()
{
const char config_yaml[] = "config.yaml";
YAML::Node config = YAML::LoadFile(config_yaml);
if (config["lastLogin"]) {
std::cout << "Last logged in: " << config["lastLogin"].as<int>() << "\n";
}
const std::string username = config["username"].as<std::string>();
const std::string password = config["password"].as<std::string>();
std::cout << "username: '" << username << "'" << std::endl;
std::cout << "password: '" << password << "'" << std::endl;
config["lastLogin"] = (int)time(0);
std::ofstream fout(config_yaml);
fout << config;
return 0;
}# config.yaml file
lastLogin: 1441030476
password: !<!> pass1234
username: !<!> admindvp正如您在上面生成的文件中所看到的,字符串的值从引号改为"!<!>"前缀字符串。我的问题是,在转储结果中,字符串值之前的"!<!>"意味着什么。以及如何使yaml-cpp转储引号字符串与上述例子。Nodejs模块无法正确加载字符串,它将其识别为null,因此"!<!>"表示法不能用于字符串。
发布于 2015-09-01 04:58:45
这是yaml-cpp的漏洞。请参阅项目站点上的问题所在。
https://stackoverflow.com/questions/32323411
复制相似问题