C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

map::find help Rate Topic: -----

#1 krebbe  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-December 08


Dream Kudos: 0

Share |

map::find help

Posted 02 December 2008 - 03:56 AM

Hi guys.

I am now writing my master thesis in computer science and the assignment is to program a small part of a bigger project. For this i need use a map::find to find out if a element is equal to something and based on that take action. When compiling it all goes well, but at runtime it gives a segmentation fault. The problem is I cannot see the error in my code, and have the last few hours stared myself blind on it. Any help would be appreciated.


if(tag.m_vecAttribute.size() > 0);
	{
		KBAttrTable* pAttrTable;
		map<string, KBAttrTable*>::iterator it;
		it = m_mapstrpTagTable.find(tag.m_strTagName);
 				
		if(it == m_mapstrpTagTable.end())			
		{
			Do something	
		}

		else
		{
			Do something else
		}

		for(int i=0; i< tag.m_vecAttribute.size(); i++)
		{
			Do something with the map
		}
	}	




I have localized the segmentation fault to the "it = m_mapstrpTagTable.find(tag.m_strTagName);" line but I cannot for my life see any errors in it.

Thanks in advance guys.
Was This Post Helpful? 0
  • +
  • -


#2 janotte  Icon User is offline

  • code > sword
  • Icon

Reputation: 281
  • View blog
  • Posts: 3,102
  • Joined: 28-September 06


Dream Kudos: 0

Expert In: C/C++

Re: map::find help

Posted 02 December 2008 - 04:15 AM

Apologies if this is a lesson in how to suck eggs but if you are using GCC are you aware of this?:
http://gcc.gnu.org/bugs/segfault.html
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Rama-llama-ding-dong
  • Icon

Reputation: 1334
  • View blog
  • Posts: 10,565
  • Joined: 23-August 08


Dream Kudos: 50

Expert In: Being annoyed with lazy people.

Re: map::find help

Posted 02 December 2008 - 05:35 AM

You're writing your Master's thesis and you don't know how to debug a seg fault? Looks like I need to take my GRE and get into a Master's program!

Seriously though, janotte's advice is sound. Run the program in a debugger, then evaluate the state of the variables you're using when the program crashes. There are tutorials here on using a couple of different debuggers.
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users