为什么unique函数会出现这样的情况?

Fisheep1024 2017-12-16 08:52:11
如下,我使用unique函数后,删除的重复数字是8,却在末尾变成了10.。。
int a[] = { 8,7,8,10,4,2,1 };
vector<int> v(a, a+7);
sort(v.begin(),v.end());
//int size = unique(v.begin(), v.end())-v.begin();
//cout << size;
for (int t = 0; t < 7; t++)
{
cout << v.at(t);
}


换一组还是如此:
int a[] = { 8,7,8,10,2,2,2 };
vector<int> v(a, a+7);
sort(v.begin(),v.end());
//int size = unique(v.begin(), v.end())-v.begin();
//cout << size;
for (int t = 0; t < 7; t++)
{
cout << v.at(t);
}


求大神指点!!!
...全文
599 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
draculamx 2017-12-17
  • 打赏
  • 举报
回复
你可以不使用VECTOR,直接对数组a使用sort和unique函数就可以了 具体内容,可以看这篇文章: http://blog.csdn.net/tomorrowtodie/article/details/51907471
ooolinux 2017-12-16
  • 打赏
  • 举报
回复
vector 构造函数、sort函数、unique函数、at函数,参数是不是都用对的。

552

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 茶馆
社区管理员
  • 茶馆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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