C++vector迭代器用法

#include 
#include 
#include 
using namespace std;

int main()
{
    vector vecDouble = {11.1, 12.2, 13.3 ,14.4};
    vector::iterator it; //获取迭代器指针
    for(it = vecDouble.begin();it != vecDouble.end(); ++it)
    {
        cout << "值为:" << *it << endl;
    }
     cout << "逆序排序:" <<  endl;
     sort(vecDouble.begin(),vecDouble.end());
     for(it = vecDouble.begin();it != vecDouble.end(); ++it)
    {
        cout << *it << endl;
    }
    cout << "降序排序:" <<  endl;
     reverse(vecDouble.begin(),vecDouble.end());
     for(it = vecDouble.begin();it != vecDouble.end(); ++it)
    {
        cout << *it << endl;
    }
    return 0;
}
C++vector迭代器用法_第1张图片

你可能感兴趣的:(C++vector迭代器用法)