memory access violation

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;
}
 
R

Rolf Magnus

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");
....
delete xmlDoc;
delete xmlConfig;
delete xmlKeywords;
delete xmlOperators;
delete xmlKeyword;
delete xmlOperator;
}


I haven't used tinyxml yet, but are you sure that you have to delete all
those objects yourself?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top