加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 如何通过yaml-cpp加载YAML文件?

发布时间:2020-12-16 03:46:44 所属栏目:百科 来源:网络整理
导读:我是 yaml-cpp的新手,我尝试了最简单的程序,但失败了,也没有找到作者的谷歌/ github网站的答案. #include iostream#include "yaml-cpp/yaml.h"using namespace std;int main(){ YAML::Node config = YAML::LoadFile("sample.yaml"); return 0;} 来自YAML官方
我是 yaml-cpp的新手,我尝试了最简单的程序,但失败了,也没有找到作者的谷歌/ github网站的答案.
#include <iostream>
#include "yaml-cpp/yaml.h"

using namespace std;

int main()
{
    YAML::Node config = YAML::LoadFile("sample.yaml");
    return 0;
}

来自YAML官方网站的sample.yaml样本

--- !clarkevans.com/^invoice
invoice: 34843
date   : 2001-01-23
bill-to: &id001
    given  : Chris
    family : Dumars
    address:
        lines: |
            458 Walkman Dr.
            Suite #292
        city    : Royal Oak
        state   : MI
        postal  : 48046
ship-to: *id001
product:
    - sku         : BL394D
      quantity    : 4
      description : Basketball
      price       : 450.00
    - sku         : BL4438H
      quantity    : 1
      description : Super Hoop
      price       : 2392.00
tax  : 251.42
total: 4443.52
comments: >
    Late afternoon is best.
    Backup contact is Nancy
    Billsmer @ 338-4338.

错误消息如下:

libc++abi.dylib: terminating with uncaught exception of type YAML::BadFile: yaml-cpp: error at line 0,column 0: bad file

我可以知道这是什么问题吗?它是库构建问题还是YAML语法问题或API使用问题?

发展环境

MacOSX10.9 c 11 IDE:QtCreator3.0.1 yaml-cpp 0.5.1

[解决了]
我犯了愚蠢的错误,我加载了错误的sample.yaml路径.

解决方法

看来yaml-cpp无法找到您的文件.你能加载任何文件吗?确保该文件位于程序的工作目录中,为了保持合理性,请确保首先加载一个非常简单的文件.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读