在网上看到下面的代码,放到VC下运行出错:error C2665: 'ostream_iterator<int,char,struct std::char_traits<char> >::ostream_iterator<int,char,struct std::char_traits<char> >' : none of the 2 overloads can convert parame
ter 1 from type 'class ostream_withassign',求指导
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <vector>
using namespace std;
void Display(vector<int>& v,const char* s);
int main()
{
srand(time(NULL));
vector<int> collection(10);
for(int i = 0; i<10;i++)
collection[i] = rand()%100;
Display(collection,"Before sorting");
sort(collection.begin(),collection.end());
Display(collection,"After sorting");
return 0;
}
void Display(vector<int>& v,const char* s)
{
cout<<endl<<s<<endl;
copy(v.begin(),v.end(),ostream_iterator<int>(cout,"\t"));
cout<<endl;
}
不知道你用的是VC的哪个版本
楼主可以试试把#include <iostream.h>改成#include <iostream>(去掉.h)