#include <iostream>
#include <map>
int main()
{
std::map<int, int> mapTest ;
for (int i = 0 ; i <10 ; i++)
{
mapTest[i] = 10*i ;
}
std::map<int, int>::iterator mapIt ;
mapIt = mapTest.find(10) ;
/*
if (mapIt != NULL)
std::cout << "mapIt = " << mapIt->second << std::endl ;
*/ // Error occur: the iterator might not find out its error.
if (mapIt != mapTest.end())
std::cout << "mapIt = " << mapIt->second << std::endl ;
int i ;
std::cin >> i ;
return 0 ;
}
My friend saw my source code, and adviced to me that the code will be broken from map's iterator.
So, I simply tested this source. I could find out where the problem occured.
However, I can't explain why the error occurs. I need to study about STL, especially map.
- ps.
This blog is for my English abilities, and I'm not good at communicating in English. If you see grammatic, syntax or logical errors, or if you can't understand clearly, PLEASE COMMENT ON IT. Your comments definitely help me, and I will really appreciate this. :)