C++编程实现对vector元素的访问
程序如下所示:
#include
#include
using namespace std;
void printfValues(vector::const_iterator beg,vector::const_iterator end)
{
while(beg!=end)
{
cout<<*beg++;
if(beg!=end)
cout<<" ";
}
}
int main()
{
vector values;
int datas;
cout<<"please enter datas(Ctrl+Z to end):"<<endl;
while(cin>>datas)
{
values.push_back(datas);
}
vector::const_iterator begg=values.begin();
vector::const_iterator endd=values.end();
printfValues(begg,endd);
cout<<endl;
return 0;
}