473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 3597
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bengt Richter | last post by:
Python 2.3.2 (#49, Oct 2 2003, 20:02:00) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.mktime((1969, 12, 31, 17, 0, 0, 0, 0, 0))...
0
by: Steven Reddie | last post by:
In article <slrnbnj19j.av.juergen@monocerus.manannan.org>, Juergen Heinzl wrote: >In article <f93791bd.0309282133.650da850@posting.google.com>, Steven Reddie wrote: >> I understand that access...
3
by: Kyle Teague | last post by:
I have a list of pointers to structs as a private member of a class. If I call begin() in the same function as I added the data then no access violation occurs. However, if I try to call begin() in...
1
by: BillyO | last post by:
In the attached code fragment I have a buffer overflow and a memory access violation. When I run the code .Net fails to verify the IL because of the buffer overflow and I get an exception as...
0
by: techie | last post by:
Hi, I've created a COM object in VC++ that I call from XMetal. I pass the COM object (via a XMetal macro) my XMetal Application object by a put_ method. In my put_ method I call QueryInterface...
12
by: aling | last post by:
Have following code snip: struct struc { int member1; int member2; } ; printf("&((struc*)0)->member2=%p\n", &((struc*)0)->member2); In VC7.1, the output is 4, the offset of member2 in struc.
1
by: zombek | last post by:
Hi. When I comipile my program (source at the bottom) with : g++ -O2 -static it gives me 'memory access violation' warning and when I dont use -O2 it doesn't. I need to use -O2 because my...
4
by: tuxman | last post by:
Hi all. First of all let me apologize by my english. I've googled a lot about my problem, but I had not find anything conclusive. I have the following piece of code: vector < map < int , char *...
6
by: nmehring | last post by:
I have an MFC app with 2000 users. I have one user that experiences a crash in our software anywhere from 1 to 5 times a week when opening a particular module. No other users have reported this...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.