vector问题 基本是照书超的可是还是不能运行
#include<iostream>#include<vector>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
void show(vector<int>::const_iterator first,vector<int>::const_iterator last){
cout<<"{";
std::copy(first, last,std::ostream_iterator<int>(cout," "));
cout<<"}"<<endl;
}
void in(const vector<int>& v){
cout<<"vector has"<<v.size()<<"elements:";
show(v.begin(),v.end());
}
int main(void){
vector<int> v;
cout<<"new vector created"<<endl;
in(v);
cout<<"filling vector from away"<<endl;
int values[]={1,3,5,7};
v.insert(v.end(),values+1,values+3);
in(v);
cout<<"appending value 5"<<endl;
v.push_back(5);
in(v);
cout<<"erase element at offset 1"<<endl;
v.erase(&v[1]);
in(v);
cout<<"inserting element 4 at offset 1"<<endl;
v.insert(v.begin()+1,4);
in(v);
cout<<"clearing allenements"<<endl;
v.clear();
in(v);
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
错误 1 error C2039: “ostream_iterator”: 不是“std”的成员 d:\documents\visual studio 2010\projects\pkjnb\pkjnb\jhgvcvghjk.cpp 10 1 pkjnb
错误 3 error C2062: 意外的类型“int” d:\documents\visual studio 2010\projects\pkjnb\pkjnb\jhgvcvghjk.cpp 10 1 pkjnb
错误 2 error C2065: “ostream_iterator”: 未声明的标识符 d:\documents\visual studio 2010\projects\pkjnb\pkjnb\jhgvcvghjk.cpp 10 1 pkjnb
错误 4 error C2664: “std::_Vector_iterator<_Myvec> std::vector<_Ty>::erase(std::_Vector_const_iterator<_Myvec>)”: 不能将参数 1 从“int *”转换为“std::_Vector_const_iterator<_Myvec>” d:\documents\visual studio 2010\projects\pkjnb\pkjnb\jhgvcvghjk.cpp 29 1 pkjnb
5 IntelliSense: namespace "std" 没有成员 "ostream_iterator" d:\documents\visual studio 2010\projects\pkjnb\pkjnb\jhgvcvghjk.cpp 10 29 pkjnb
6 IntelliSense: 不允许使用类型名 d:\documents\visual studio 2010\projects\pkjnb\pkjnb\jhgvcvghjk.cpp 10 46 pkjnb
8 IntelliSense: 函数调用中的参数太少 d:\documents\visual studio 2010\projects\pkjnb\pkjnb\jhgvcvghjk.cpp 29 15 pkjnb
7 IntelliSense: 没有与参数列表匹配的 重载函数 "std::vector<_Ty, _Ax>::erase [其中 _Ty=int, _Ax=std::allocator<int>]" 实例 d:\documents\visual studio 2010\projects\pkjnb\pkjnb\jhgvcvghjk.cpp 29 3 pkjnb
问题主要出在第10行和29行. 那位能帮我改下。