用反向迭代器和普通迭代器逆序输出…

int main (int argc, char* argv[])
{
    vectornumbers;
    cout << "vector:" << endl;
    for (int i = 0; i < 10; ++i) {
        numbers.push_back (i);
        cout << i << " ";
    }
    cout << endl << "---------------------------------------" << endl;
    cout << "用反向迭代器逆序输出vector:" << endl;
    for_each (numbers.crbegin (), numbers.crend (), [] (const int &i){cout << i << " "; });
    cout <<endl << "---------------------------------------" << endl;
    cout << "用普通迭代器逆序输出vector:" << endl;
    for (auto it = numbers.cend (); it > numbers.begin ();)
        cout << *--it << " ";
    cout << endl;
    return 0;
}
posted @ 2014-07-18 21:07  wu_overflow  阅读(485)  评论(0编辑  收藏  举报