65,211
社区成员
发帖
与我相关
我的任务
分享
//工具VC6.0
#include <iostream>
#include <vector>
using namespace std;
template <class ForwardIterator, class T>
ForwardIterator find_linear(ForwardIterator first, ForwardIterator last, T value)
{
while (first!=last)
if (*first++==value)
return --first;
return last;
}
void test()
{
vector <int> v(4, 1); //第一步申请查看memory,v起始地址为0x004800e0
v.insert(v.end()-1,7); // 执行完这步以后,v起始地址竟然成了0x004800e0,而且原来的0x004800e0这段地址全成乱码了,不解ING
vector <int>::iterator i = find_linear(v.begin(),v.end(),7);
cout <<v[3] <<endl;
if (i!=v.end())
cout <<*i <<endl;
else
cout <<"NOT FOUND" <<endl;
}
int main()
{
int i;
test();
}
vector < int >v (4, 1);
cout << "size of vector is " << v.size() << endl; //输出为4
cout << "capacity of vector is " << v.capacity() << endl;//输出为4
v.insert (v.end () - 1, 7);
cout << "size of vector is " << v.size() << endl;//输出为5
cout << "capacity of vector is " << v.capacity() << endl;//输出为8
vector <int> v(4, 1); //第一步申请查看memory,v起始地址为0x004800e0
v.insert(v.end()-1,7); // 执行完这步以后,v起始地址竟然成了0x004800e0,而且原来的0x004800e0这段地址全成乱码了,不解ING