#include "stdafx.h"
#include "Plist.hpp"
#include <iostream>
using namespace std;
using namespace::Plist;
int _tmain(int argc, _TCHAR* argv[])
{
dictionary_type dict;
Plist::readPlist("XMLExample1.plist", dict);
for(dictionary_type::const_iterator it = dict.begin(); it != dict.end(); ++it)
{
cout<< "key: "<< it->first <<endl;
}
//读数组
const array_type& plistArray = boost::any_cast<const array_type&>(dict.find("testArray")->second);
cout << boost::any_cast<const int64_t&>(plistArray[0]) << endl;
cout << boost::any_cast<const string&>(plistArray[1]).c_str() << endl;
//读字典
const dictionary_type& plistDic = boost::any_cast<const dictionary_type&>(dict.find("testDict")->second);
dictionary_type::const_iterator it = plistDic.begin();
cout << "key:" << it->first << endl;
cout << boost::any_cast<const string&>(it->second) << endl;
//读一个变量
const Date& date = boost::any_cast<const Date&>(dict.find("testDate")->second);
std::string strDate = date.timeAsXMLConvention();
/*
缺点:读取的数据类型不好动态判断,因为,读出的数据都放到了boost::any中了,类型无法认为识别。
*/
return 0;
}
#include "Plist.hpp"
#include <iostream>
using namespace std;
using namespace::Plist;
int _tmain(int argc, _TCHAR* argv[])
{
dictionary_type dict;
Plist::readPlist("XMLExample1.plist", dict);
for(dictionary_type::const_iterator it = dict.begin(); it != dict.end(); ++it)
{
cout<< "key: "<< it->first <<endl;
}
//读数组
const array_type& plistArray = boost::any_cast<const array_type&>(dict.find("testArray")->second);
cout << boost::any_cast<const int64_t&>(plistArray[0]) << endl;
cout << boost::any_cast<const string&>(plistArray[1]).c_str() << endl;
//读字典
const dictionary_type& plistDic = boost::any_cast<const dictionary_type&>(dict.find("testDict")->second);
dictionary_type::const_iterator it = plistDic.begin();
cout << "key:" << it->first << endl;
cout << boost::any_cast<const string&>(it->second) << endl;
//读一个变量
const Date& date = boost::any_cast<const Date&>(dict.find("testDate")->second);
std::string strDate = date.timeAsXMLConvention();
/*
缺点:读取的数据类型不好动态判断,因为,读出的数据都放到了boost::any中了,类型无法认为识别。
*/
return 0;
}
本文介绍了一个C++程序如何使用Plist库来解析名为XMLExample1.plist的文件,并展示了如何读取其中的字典、数组及特定变量等元素。通过迭代器遍历字典并打印键值,同时演示了获取数组和字典内特定类型的值的方法。
3304

被折叠的 条评论
为什么被折叠?



