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

前端之家收集整理的这篇文章主要介绍了c – 如何通过yaml-cpp加载YAML文件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 yaml-cpp的新手,我尝试了最简单的程序,但失败了,也没有找到作者的谷歌/ github网站的答案.
  1. #include <iostream>
  2. #include "yaml-cpp/yaml.h"
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. YAML::Node config = YAML::LoadFile("sample.yaml");
  9. return 0;
  10. }

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

  1. --- !clarkevans.com/^invoice
  2. invoice: 34843
  3. date : 2001-01-23
  4. bill-to: &id001
  5. given : Chris
  6. family : Dumars
  7. address:
  8. lines: |
  9. 458 Walkman Dr.
  10. Suite #292
  11. city : Royal Oak
  12. state : MI
  13. postal : 48046
  14. ship-to: *id001
  15. product:
  16. - sku : BL394D
  17. quantity : 4
  18. description : Basketball
  19. price : 450.00
  20. - sku : BL4438H
  21. quantity : 1
  22. description : Super Hoop
  23. price : 2392.00
  24. tax : 251.42
  25. total: 4443.52
  26. comments: >
  27. Late afternoon is best.
  28. Backup contact is Nancy
  29. 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无法找到您的文件.你能加载任何文件吗?确保该文件位于程序的工作目录中,为了保持合理性,请确保首先加载一个非常简单的文件.

猜你在找的C&C++相关文章