c++ yaml-cpp库解析yaml
2022-03-11 本文已影响0人
一路向后
1.config.yaml
username: helen
password: 123456
2.源码实现
#include <iostream>
#include <yaml-cpp/yaml.h>
using namespace std;
int main()
{
YAML::Node config = YAML::LoadFile("config.yaml");
const std::string username = config["username"].as<std::string>();
const std::string password = config["password"].as<std::string>();
cout << username << endl;
cout << password << endl;
return 0;
}
3.编译源码
$ g++ -o test test.cpp -std=c++11 -lyaml-cpp
4.运行及其结果
$ ./test
helen
123456