#include <iostream> #include "yaml-cpp/yaml.h" int main() { // 从文件中加载YAML数据 YAML::Node data = YAML::LoadFile("data/data.yaml"); // 读取数据 std::string name = data["name"].as<std::string>(); int age = data["age"].as<int>(); const YAML::Node& hobbies = data...
int read_yaml(std::string read_path) { try { // 读取YAML文件 YAML::Node config = YAML::LoadFile(read_path); // 访问YAML中的数据 std::string name = config["name"].as<std::string>(); int age = config["age"].as<int>(); std::string city = config["city"].as<std::string>...
#include<yaml-cpp/yaml.h>#include<iostream>#include<string>#include<fstream>using std::cout;using std::endl;intmain(int argc,char*argv[]){YAML::Node config=YAML::LoadFile("config.yaml");if(config["lastLogin"]){std::cout<<"Last logged in: "<<config["lastLogin"].as<std::string>(...
YAML::Node load(const std::string &file) { printf("load %s.\n", file.c_str()); YAML::Node config = YAML::LoadFile(file); if(config.Type() == YAML::NodeType::value::Undefined || config.Type() == YAML::NodeType::value::Null || config.Type() == YAML::NodeType::value::Sca...
YAML::Node config = YAML::LoadFile("../config.yaml");cout<<"name:"<< config["name"].as<string>() <<endl;cout<<"sex:"<< config["sex"].as<string>() <<endl;cout<<"age:"<< config["age"].as<int>() <<endl;return0; ...
#include <yaml-cpp/yaml.h> #include <fstream> #include <iostream> int main() { // 加载 YAML 文件 YAML::Node config = YAML::LoadFile("config.yaml"); // 访问 YAML 数据 std::string name = config["name"].as<std::string>(); int age = config["age"...
cout << node1[0].as<string>() << endl; cout << node2[0].as<int>() << endl; // 输出元素 1. 2. 3. 4. 更多API参考yaml-cpp docs。 示例: a、CMakeLists.txt AI检测代码解析 cmake_minimum_required(VERSION 2.8) ...
std::string name_; int age_; }; 3. 为Person类提供序列化和反序列化的功能。为此,我们需要包含YAML-CPP库的头文件,并使用YAML::convert函数: #include <yaml-cpp/yaml.h> namespace YAML { template<> struct convert<Person> { static Node encode(const Person& rhs) { ...
const std::string username = config["username"].as<std::string>(); const std::string password = config["password"].as<std::string>(); login(username, password); config["lastLogin"] = getCurrentDateTime(); std::ofstream fout("config.yaml"); ...
#include <string> #include <fstream> #include <yaml-cpp/yaml.h> int test_parse_yaml_file(){ #ifdef _MSC_VER YAML::Node config = YAML::LoadFile("E:/GitCode/Messy_Test/testdata/test_yaml-cpp.yml");#else YAML::Node config = YAML::LoadFile("testdata/test_yaml-cpp.yml");#endif ...