yaml-cpp/main.cpp

40 lines
802 B
C++
Raw Normal View History

#include "parser.h"
#include "node.h"
#include "exceptions.h"
2008-06-30 10:51:22 +04:00
#include <fstream>
#include <iostream>
2008-06-26 02:45:08 +04:00
int main()
{
2008-06-30 10:51:22 +04:00
std::ifstream fin("test.yaml");
try {
YAML::Parser parser(fin);
if(!parser)
return 0;
YAML::Document doc;
parser.GetNextDocument(doc);
const YAML::Node& root = doc.GetRoot();
for(YAML::Node::Iterator it=root.begin();it!=root.end();++it) {
std::string name;
(*it)["name"] >> name;
std::cout << "Name: " << name << std::endl;
int age;
(*it)["age"] >> age;
std::cout << "Age: " << age << std::endl;
std::string school;
(*it)["school"] >> school;
std::cout << "School: " << school << std::endl;
}
} catch(YAML::Exception& e) {
std::cout << "Error parsing the yaml!\n";
}
getchar();
2008-06-26 02:45:08 +04:00
return 0;
}