locked
Find the problems in this c program RRS feed

  • Question

  • The following program has at least four iterator-related problems. How many can you find?

    int main() 
    {
    vector<Date> e;
    copy( istream_iterator<Date>( cin ),
    istream_iterator<Date>(),
    back_inserter( e ) );
    vector<Date>::iterator first =
    find( e.begin(), e.end(), "01/01/95" );
    vector<Date>::iterator last =
    find( e.begin(), e.end(), "12/31/95" );
    *last = "12/30/95";
    copy( first,
    last,
    ostream_iterator<Date>( cout, "\n" ) );
    e.insert( --e.end(), TodaysDate() );
    copy( first,
    last,
    ostream_iterator<Date>( cout, "\n" ) );
    }


    Tuesday, October 2, 2007 7:23 AM