How to download YAML file through yaml-cpp?

I am very new to yaml-cpp , I tried a simple program, but could not, and also did not find an answer from the author google / github site.

#include <iostream> #include "yaml-cpp/yaml.h" using namespace std; int main() { YAML::Node config = YAML::LoadFile("sample.yaml"); return 0; } 

sample.yaml sample from the official YAML website

  ---! 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.

The error message is displayed as follows:

libC ++ abi.dylib: termination with an uncaught exception of type YAML :: BadFile: yaml-cpp: error in row 0, column 0: bad file

May I find out what the problem is? Is this a problem with building a library, or is it a YAML or API syntax problem using the problem?

development environment

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


[SOLVED]
I made a stupid mistake that I loaded the wrong sample.yaml path.

+6
source share
2 answers

It seems that yaml-cpp cannot find your file. Could you upload any file? Make sure the file is in the working directory of your program, and for the sake of common sense, make sure that you can download a very simple file first.

+2
source

I think the YAML parser in the yaml-cpp version that you use is simply not well developed to handle the first line of your sample file. The sample file attempts to illustrate some of the more advanced features of YAML. It seems that your parser cannot handle all of these. I suggest you start with a simpler example file.

I checked your file with three online validators with the following results:

Sure, the file has a YAML value, but this does not mean that all existing parsers can parse it!

+6
source

All Articles