Z
zombek
Hi.
I'm quite a begginer. I wanted to learn the usage of tinyxml library so
I wrote a little program which compiles on g++ 4.1.1 with -O2 -Wall,
but when I run it a get a message "memory access violation". Source:
#include "tinyxml.h"
#include <vector>
#include <string>
#include <iostream>
using namespace std;
const string XML_FILE = "test.xml";
vector<string> keywords;
vector<string> operators;
int main() {
TiXmlDocument* xmlDoc = new TiXmlDocument(XML_FILE.c_str());
TiXmlElement* xmlConfig = xmlDoc->FirstChildElement("config");
TiXmlElement* xmlKeywords =
xmlConfig->FirstChildElement("keywords");
TiXmlElement* xmlOperators =
xmlConfig->FirstChildElement("operators");
TiXmlElement* xmlKeyword = xmlKeywords->FirstChildElement("value");
string keyword;
while(xmlKeyword) {
keyword = xmlKeyword->GetText();
keywords.push_back(keyword);
xmlKeyword = xmlKeywords->FirstChildElement("value");
}
TiXmlElement* xmlOperator =
xmlOperators->FirstChildElement("value");
string operatr;
while(xmlOperator) {
operatr = xmlOperator->GetText();
operators.push_back(operatr);
xmlOperator = xmlOperators->FirstChildElement("value");
}
cout << "keywords" << endl;
for(unsigned int i = 0; i < keywords.size(); i++) {
cout << keywords.at(i) << endl;
}
cout << "operators" << endl;
for(unsigned int i = 0; i < operators.size(); i++) {
cout << operators.at(i) << endl;
}
delete xmlDoc;
delete xmlConfig;
delete xmlKeywords;
delete xmlOperators;
delete xmlKeyword;
delete xmlOperator;
}
I'm quite a begginer. I wanted to learn the usage of tinyxml library so
I wrote a little program which compiles on g++ 4.1.1 with -O2 -Wall,
but when I run it a get a message "memory access violation". Source:
#include "tinyxml.h"
#include <vector>
#include <string>
#include <iostream>
using namespace std;
const string XML_FILE = "test.xml";
vector<string> keywords;
vector<string> operators;
int main() {
TiXmlDocument* xmlDoc = new TiXmlDocument(XML_FILE.c_str());
TiXmlElement* xmlConfig = xmlDoc->FirstChildElement("config");
TiXmlElement* xmlKeywords =
xmlConfig->FirstChildElement("keywords");
TiXmlElement* xmlOperators =
xmlConfig->FirstChildElement("operators");
TiXmlElement* xmlKeyword = xmlKeywords->FirstChildElement("value");
string keyword;
while(xmlKeyword) {
keyword = xmlKeyword->GetText();
keywords.push_back(keyword);
xmlKeyword = xmlKeywords->FirstChildElement("value");
}
TiXmlElement* xmlOperator =
xmlOperators->FirstChildElement("value");
string operatr;
while(xmlOperator) {
operatr = xmlOperator->GetText();
operators.push_back(operatr);
xmlOperator = xmlOperators->FirstChildElement("value");
}
cout << "keywords" << endl;
for(unsigned int i = 0; i < keywords.size(); i++) {
cout << keywords.at(i) << endl;
}
cout << "operators" << endl;
for(unsigned int i = 0; i < operators.size(); i++) {
cout << operators.at(i) << endl;
}
delete xmlDoc;
delete xmlConfig;
delete xmlKeywords;
delete xmlOperators;
delete xmlKeyword;
delete xmlOperator;
}