首页 新闻 赞助 找找看

stl流和迭代器

0
悬赏园豆:10 [已解决问题] 解决于 2011-11-22 08:20

在网上看到下面的代码,放到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;
}

ttssrs的主页 ttssrs | 初学一级 | 园豆:82
提问于:2011-05-04 13:07
< >
分享
最佳答案
0

不知道你用的是VC的哪个版本

楼主可以试试把#include <iostream.h>改成#include <iostream>(去掉.h)

收获园豆:10
laocai_liu | 菜鸟二级 |园豆:230 | 2011-05-07 14:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册