C++ Yaml文件解析安装及使用 yaml-cpp

安装 yaml-cpp

克隆官方库

git clone https://github.com/jbeder/yaml-cpp.git

编译 yaml-cpp

cd yaml-cpp # 进入克隆的文件夹
mkdir build
cd build
cmake ..
make
make install

没出现报错的话就完成了编译

示例代码

robot.cpp

#include "yaml-cpp/yaml.h" //安装yaml-cpp参考google code 主页
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

// our data types //这个例子好像是取自开源游戏引擎ogre,随便说的
struct Vec3 {
     //位置坐标
   float x, y, z;
};

struct Power {
     //招式,魔法
   std::string name; //招式名字,如 葵花宝典
   int damage; //伤害值
};

struct Monster {
     //怪兽
   std::string name;
   Vec3 position;
   std::vector <Power> powers;
};

// now the extraction operators for these types //重载 >> 预算符。。。。
void operator >> (const YAML::Node& node, Vec3& v) {
    
   node[0] >> v.x;
   node[1] >> v.y;
   node[2] >> v.z;
}

void operator >> (const YAML::Node& node, Power& power) 
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值