大家帮我看看这段小代码

y1018799688 2011-03-22 10:24:22

#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
#include<iterator>
#include<fstream>
using namespace std;

int main()
{
istream_iterator<int> cin_it(cin);
istream_iterator<int> end_of_stream;
vector<int> vec(cin_it,end_of_stream);
sort(vec.begin(),vec.end());
ostream_iterator<int> output(cout," ");
unique_copy(vec.begin(),vec.end(),output);
}

编译时出现这个错误--------------------Configuration: a - Win32 Debug--------------------
Compiling...
a.cpp
E:\C\a.cpp(13) : error C2664: '__thiscall std::vector<int,class std::allocator<int> >::std::vector<int,class std::allocator<int> >(unsigned int,const int &,const class std::allocator<int> &)' : cannot convert parameter 1 from 'class std::istream_ite
rator<int,char,struct std::char_traits<char> >' to 'unsigned int'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
E:\C\a.cpp(17) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.

a.exe - 1 error(s), 0 warning(s)
大家帮我看看怎么改改
...全文
94 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
y1018799688 2011-03-22
  • 打赏
  • 举报
回复
看来是编译器问题了,谢谢大家咯
pengzhixi 2011-03-22
  • 打赏
  • 举报
回复
vs2008,dev都没任何问题
無_1024 2011-03-22
  • 打赏
  • 举报
回复
嗯楼上正解 换个编译器 VS2010可以运行
y1018799688 2011-03-22
  • 打赏
  • 举报
回复
怎么改呢,书上就是这样写的
pengzhixi 2011-03-22
  • 打赏
  • 举报
回复
换个编译器吧。
hhh_hao 2011-03-22
  • 打赏
  • 举报
回复

istream_iterator<int> cin_it(cin);
istream_iterator<int> end_of_stream;
vector<int> vec(cin_it,end_of_stream)


这段代码没看懂是什么意思
無_1024 2011-03-22
  • 打赏
  • 举报
回复
vector<int> vec(cin_it,end_of_stream);
参数类型应该是迭代器 而不是两个对象的范围

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧