Probelm with std::ma find function
-
Hello everyone, I am using std::map in my application. I am searching for CMyStruct based on the CString using find function. But sometimes find function is returning null iterator even when there is strcture obj with specified key. Can anyone help me in finding the solution?
-
Hello everyone, I am using std::map in my application. I am searching for CMyStruct based on the CString using find function. But sometimes find function is returning null iterator even when there is strcture obj with specified key. Can anyone help me in finding the solution?
Posting the relevant code would possibly help. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hello everyone, I am using std::map in my application. I am searching for CMyStruct based on the CString using find function. But sometimes find function is returning null iterator even when there is strcture obj with specified key. Can anyone help me in finding the solution?
Lakshmi_p wrote:
sometimes find function is returning null iterator even when there is strcture obj with specified ke
Umm, that's odd. If the key doesn't exist in the sequence
std::map::find()
returnsend()
and notNULL
. Have you verified that you haven't added a NULL pointer for the key you're looking for? If the answer to this question is 'no', don't bother answering the following. ;-) How have you declared your map? Post some code (preferrably properly formatted using <pre></pre> tags) How do you add elements to the sequence? (Code again)"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
Posting the relevant code would possibly help. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Hi, here is how I used std::mapmapVar; void Myfun1() { ... CString strTemp = "str1"; mapVar[strTemp] = myStructObj1; } void MyFun2() { map<CString, CMyStruct>::const_iterator itr; Cstring strTemp = "str1"; itr = mapVar.find(strTemp); .... } Sometimes it is working fine but sometimes it is not working.