#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. :)
'old_Coding > C/C++' 카테고리의 다른 글
[effective C++] 7장. 템플릿과 일반화 프로그래밍-41, 42 (3) | 2011.08.08 |
---|---|
[C/C++] 문자열 다루기(1) - 초기화 (0) | 2010.12.13 |
[C] File I/O (0) | 2010.03.11 |
[Scrap] Struct SYSTEM_INFO (*) (0) | 2010.01.04 |
[C++] Function Pointer(3) (Solution) (0) | 2009.12.27 |