mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-04 05:51:27 +12:00
Added an iterator class that can iterate through both sequence and map nodes.
This commit is contained in:
parent
f7358701f2
commit
d56b54b34f
16 changed files with 393 additions and 105 deletions
31
main.cpp
31
main.cpp
|
@ -1,18 +1,39 @@
|
|||
#include "parser.h"
|
||||
#include "node.h"
|
||||
#include "exceptions.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::ifstream fin("test.yaml");
|
||||
YAML::Parser parser(fin);
|
||||
|
||||
YAML::Document doc;
|
||||
while(parser) {
|
||||
std::cout << "---\n";
|
||||
try {
|
||||
YAML::Parser parser(fin);
|
||||
if(!parser)
|
||||
return 0;
|
||||
|
||||
YAML::Document doc;
|
||||
parser.GetNextDocument(doc);
|
||||
std::cout << 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();
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue