创建一个含有10个整数的vector对象,然后使用迭代器将所有元素的值都变成原来的两倍并输出vector对象的内容
//3.23
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
//vector<int> text(10,2); //vector对象text中存入10个数字,值都为2
vector<int> text{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; //text中存入10个数字0-9
for (auto it = text.begin(); it != text.end();it++) //注意判断其是否为空
{
//*it = *it * 2;
*it *= 2; //将vector对象中的元素值变成原来的两倍并输出
cout<<*it<<endl;
}
system("pause");
return 0;
}