-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
56 lines (48 loc) · 1.3 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>
#include "tinyxml.h"
#include "tinystr.h"
#include <vector>
using namespace std;
typedef struct relationStyle
{
int DNum; //维数
vector<int> DClass; //每一维的种类
}relStyle;
bool ReadConfFile(string FileName, relStyle &rel);
int main()
{
relStyle rel;
string filename = "conf.xml";
ReadConfFile(filename, rel);
cout << rel.DNum << endl;
vector<int>::iterator irel;
for(irel = rel.DClass.begin(); irel != rel.DClass.end(); irel++)
cout << *irel << endl;
return 0;
}
bool ReadConfFile(string FileName, relStyle &rel)
{
try
{
TiXmlDocument *myDocument = new TiXmlDocument(FileName.c_str());
myDocument->LoadFile();
TiXmlElement *RootElement = myDocument->RootElement();
TiXmlElement *DNumxml = RootElement->FirstChildElement();
int DNum = atoi(DNumxml->GetText());
rel.DNum = DNum;
int i;
TiXmlElement *D = DNumxml->NextSiblingElement();
for(i = 0; i < DNum; i++)
{
TiXmlElement *DClass = D->FirstChildElement();
rel.DClass.push_back(atoi(DClass->GetText()));
D = D->NextSiblingElement();
}
}
catch (string& e)
{
return false;
}
return true;
}