int main()
{
vector<int> vi;
vi.reserve(10);
// back_insert_iterator<vector<int> > iter(vi);
vector<int>::iterator iter = vi.begin();
*iter = 1;
++iter;
*iter = 2;
++iter;
*iter = 3;
back_insert_iterator<std::__1::vector<int> > iterb(vi);
back_inserter(vi) = 4;
back_inserter(vi) = 5;
vi.reserve(vi.size() * 2);
copy(vi.begin(), vi.end(), vi.end());
ostream_iterator<int> os(cout, " ");
copy(vi.begin(), vi.end(), os);
}
问题1,为什么cout
打印4 5
,当我预计它将打印1 2 3 4 5 1 2 3 4 5
? 问题2,当我用copy(vi.begin(), vi.end(), back_insert(vi))
替换它时,它会打印4 5 4 5
,为什么?迭代器不访问全矢量
什么是 “__1” 吗? –
我不知道,这是编译器自动添加的,我用的ide是xcode 4.6.2; –