468,469 Members | 1,979 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,469 developers. It's quick & easy.

memory access violation

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
3 3355
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
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
My misteake, i forgot about xmlDoc->LoadFile().

Sep 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bengt Richter | last post: by
reply views Thread by Steven Reddie | last post: by
3 posts views Thread by Kyle Teague | last post: by
12 posts views Thread by aling | last post: by
1 post views Thread by zombek | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.