By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,992 Members | 1,325 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,992 IT Pros & Developers. It's quick & easy.

memory access violation

P: n/a
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<stringkeywords;
vector<stringoperators;

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

Sep 10 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
zo****@gmail.com wrote:
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?

Sep 10 '06 #2

P: n/a
When I comment it out nothing changes.

Rolf Magnus napisal(a):
zo****@gmail.com wrote:
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?
Sep 10 '06 #3

P: n/a
My misteake, i forgot about xmlDoc->LoadFile().

Sep 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.