STL,编译时出错....

aa806525280 2008-11-18 09:59:44

函数功能;排序后删除重复的值
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
using namespace std;
int reduce ( int ar[],int n);
int main(){
int n=9;
int a[]={9,8,7,6,5,4,3,2,1};
reduce(a[],n);
return 0;
}
int reduce ( int ar[],int n)
{vector<int>svec(ar,ar+n);
vector<int> ::iterator pointer;
vector<int> ::iterator end;
sort(svec.begin(),svec.end()); //排序
end= unique(svec.begin(),svec.end());//连续相同的只留一个
int i=end-svec.begin();剩下元素个数
cout<<i<<endl;
for(pointer=svec.begin();pointer!=end;pointer)
cout<<*pointer<<endl;


}



...全文
168 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
SearchLife 2008-12-17
  • 打赏
  • 举报
回复
up
aa806525280 2008-12-17
  • 打赏
  • 举报
回复
请问一下,上面说的是不是都是一个意思?有点迷茫...
太乙 2008-11-19
  • 打赏
  • 举报
回复
upup~~~~~~
mujiok2003 2008-11-18
  • 打赏
  • 举报
回复



#include<iostream>
#include<vector>
//#include<functional>
#include<iterator>
#include<algorithm>

using namespace std;

void reduce(int [],int);

int main(){
int n=9;
int a[]={9,8,7,6,5,4,3,2,1};
reduce(a,n);
return 0;
}
void reduce ( int ar[],int n) {
sort(ar,ar+n);
int * end = unique(ar,ar+n);
cout << distance(ar,end) <<endl;
copy(ar, ar+n, ostream_iterator<int>(cout,"\n"));
}
aa806525280 2008-11-18
  • 打赏
  • 举报
回复
谢谢!我真是粗心,向你们学习 】
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>

using namespace std;

int reduce( int ar[],int n);

int main(){
int n=9;
int a[]={9,8,7,6,5,4,3,2,1};
reduce(a,n);
return 0;
}
int reduce ( int ar[],int n) {
vector<int> svec(ar,ar+n);
vector<int>::iterator pointer;
vector<int>::iterator end;
sort(svec.begin(),svec.end()); //排序
end= unique(svec.begin(),svec.end());//连续相同的只留一个
int i = end - svec.begin();//剩下元素个数
cout << i <<endl;
for(pointer=svec.begin();pointer!= end ;pointer++)
cout <<*pointer <<endl;

system("pause");
return 0;
}

gccdy 2008-11-18
  • 打赏
  • 举报
回复

#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>

using namespace std;

int reduce( int ar[],int n);

int main(){
int n=9;
int a[]={9,8,7,6,5,4,3,2,1};
reduce(a,n);
return 0;
}
int reduce ( int ar[],int n) {
vector<int> svec(ar,ar+n);
vector<int>::iterator pointer;
vector<int>::iterator end;
sort(svec.begin(),svec.end()); //排序
end= unique(svec.begin(),svec.end());//连续相同的只留一个
int i = end - svec.begin();//剩下元素个数
cout << i <<endl;
for(pointer=svec.begin();pointer!=svec.end();pointer++)
cout <<*pointer <<endl;

system("pause");
return 0;
}


gccdy 2008-11-18
  • 打赏
  • 举报
回复

#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>

using namespace std;

int reduce( int ar[],int n);

int main(){
int n=9;
int a[]={9,8,7,6,5,4,3,2,1};
reduce(a,n);
return 0;
}
int reduce ( int ar[],int n) {
vector<int> svec(ar,ar+n);
vector<int>::iterator pointer;
vector<int>::iterator end;
sort(svec.begin(),svec.end()); //排序
end= unique(svec.begin(),svec.end());//连续相同的只留一个
//int i = end - svec.begin();剩下元素个数
//cout << i <<endl;
for(pointer=svec.begin();pointer!=svec.end();pointer++)
cout <<*pointer <<endl;

system("pause");
return 0;
}

wangkangsoldier 2008-11-18
  • 打赏
  • 举报
回复
编译时出什么错误?

将vector<int>svec(ar,ar+n)改成vector<int>svec(ar,ar+n-1)试试
将试试将reduce函数中的数组形参改成指针传递
aa806525280 2008-11-18
  • 打赏
  • 举报
回复
按一楼改过后,
Linking...
LINK : fatal error LNK1168: cannot open Debug/0000.exe for writing
执行 link.exe 时出错.
Non_Recursive 2008-11-18
  • 打赏
  • 举报
回复
reduce(a[],n); //reduce(a,n)

还有,请发一下错误信息

65,211

社区成员

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

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