ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • erase() 사용시 주의점.
    Algorithm & Date structure/STL 2008. 11. 25. 11:20
    728x90

    erase()는 반복자를 삭제후 그 다음위치를 리턴합니다.

    그러니 erase()를 사용후 백터의 크기를 조사해서 예외처리를 해주도록 하는게 안전하겠죠?

    std::vector<int> arrInt;
    std::vector<int>::iterlator itor = arrInt.begin();

    while ( itor != arrInt.end() )
    {
        cin << (*itor);
        itor = arrInt.erase(itor);
    }

    혹은

    std::list<int> arrInt;
    std::list<int>::iterlator itor = arrInt.begin();

    while ( itor != arrInt.end() )
    {
        cin << (*itor);
        itor = arrInt.erase(itor);
    }

    'Algorithm & Date structure > STL' 카테고리의 다른 글

    제네릭 알고리즘 - shuffle_random()  (2) 2007.03.22

    댓글

Designed by black7375.