标题:使用unique_copy算法去除重复元素无效
取消只看楼主
fxbszj
Rank: 5Rank: 5
来 自:阿修罗界
等 级:职业侠客
威 望:4
帖 子:163
专家分:331
注 册:2012-10-8
结帖率:92.86%
已结贴  问题点数:10 回复次数:0 
使用unique_copy算法去除重复元素无效
程序代码:
#include <iostream>
#include <algorithm>
#include <list>
#include <vector>
#include <string>

using namespace std;

int main()
{
  list<string> sli;
  vector<string> svec;
  string word;
  
  cout<<"Enter strings for list:"<<endl;
  while(cin>>word)
    sli.push_back(word);
  
  unique_copy(sli.begin(),sli.end(),back_inserter(svec));

  cout<<"Vector:"<<endl;
  for(vector<string>::iterator iter=svec.begin();iter!=svec.end();++iter)
    cout<<*iter<<" ";
  cout<<endl;

  return 0;
}

要求是用unique_copyde算法把一个容器中非重复的元素复制到另外一个容器中,我按照要求和提示编写了代码,可是结果总是出现最后两个容器的内容一样,求解释
搜索更多相关主题的帖子: 元素 
2013-01-10 19:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-396162-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.113099 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved