3.21
了解下begin()函数和end()函数的意义,就会迭代了吧,很简单的。
3.22
嗨呀,好气啊,C++11中的新特性cbegin()和cend()函数——指向容器的第一个元素和最后一个元素的下一个位置,都用不了。如果要使用迭代器的话,做不出来的。
3.23
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void main()
{
vector<int> text(10,5);
for (auto it = text.begin(); it != text.end();it++) //注意判断其是否为空
{
*it = *it * 2;
cout<<*it<<endl;
}
}