Vector 컨테이너에서 시작 위치와 갯수만큼 컨테이너 복사하기
int _tmain(int argc, _TCHAR* argv[])
{
    typedef std::vector< int > VecInts;

    VecInts vecInts;
    vecInts.push_back(0);
    vecInts.push_back(1);
    vecInts.push_back(2);
    vecInts.push_back(3);
    vecInts.push_back(4);
    vecInts.push_back(5);
    vecInts.push_back(6);
    vecInts.push_back(7);
    vecInts.push_back(8);
    vecInts.push_back(9);

    const size_t startIndex = 3;
    const size_t count = 3;

    VecInts::iterator it_begin = (startIndex >= vecInts.size()) ? vecInts.end() : vecInts.begin() + startIndex;
    VecInts::iterator it_end = (count >= std::distance(it_begin, vecInts.end())) ? vecInts.end() : it_begin + count;

    VecInts vecDest;
    std::copy(it_begin, it_end, std::back_inserter(vecDest));

    std::for_each(vecDest.begin(), vecDest.end(),
        [](const int elem)
    {
        std::cout << elem << std::endl;
    });

    return 0;
}
2013/09/06 18:13 2013/09/06 18:13

글 걸기 주소 : 이 글에는 트랙백을 보낼 수 없습니다

덧글을 달아 주세요