1.注意:千万不要把迭代器当作第一元素的地址来传递。 Vector 迭代器是由实作版本定义的,也许并不是一般的指针。
Printf(“%s\n”, v.begin()); // ERROR (might work, but not portable)
Prinft(“%s\n”, &v[0]); // OK
2.如果高效率是你的最高目标,你应该优先选用成员函数。 p117
#if 1
coll.remove(4); // good Perfomance
#else
coll.erase(remove(coll.begin(), coll.end(), 3), coll.end()); // poor Perfomance
#endif
3-注意:临时对象不可以作修改( 特别提醒,以下对于 VC++ 是没有问题的)
e.g. std::vector<int> coll;
sort(++coll.begin(), coll.end() ); // 这里无法通过编辑
可以通过如下解决:(加入一个辅助对象)
e.g. std::vector<int> coll;
std::vector<int>::iterator beg = coll.begin();
sort(++beg, coll.end() );
Printf(“%s\n”, v.begin()); // ERROR (might work, but not portable)
Prinft(“%s\n”, &v[0]); // OK
2.如果高效率是你的最高目标,你应该优先选用成员函数。 p117
#if 1
coll.remove(4); // good Perfomance
#else
coll.erase(remove(coll.begin(), coll.end(), 3), coll.end()); // poor Perfomance
#endif
3-注意:临时对象不可以作修改( 特别提醒,以下对于 VC++ 是没有问题的)
e.g. std::vector<int> coll;
sort(++coll.begin(), coll.end() ); // 这里无法通过编辑
可以通过如下解决:(加入一个辅助对象)
e.g. std::vector<int> coll;
std::vector<int>::iterator beg = coll.begin();
sort(++beg, coll.end() );