练习3.23

编写一段程序,创建一个含有10个整数的vector对象,然后使用迭代器将所有元素的值都变成原来的两倍。输出vector对象的内容,检验程序是否正确。


#include <iostream>
#include <vector>
#include <cctype>
using namespace std;
using std::vector;
    int main(){
        vector<int> v1={1,2,3,4,5,6,7,8,9,2};
        for(auto a=v1.begin();a!=v1.end();a++)
            *a=*a*2;
            for(int i=0;i<10;i++)
        cout<<v1[i]<<endl;
        return 0;
}


posted @ 2014-12-25 15:21  Song_4  阅读(159)  评论(0)    收藏  举报