Unique_copy不返回预期的输出
Unique_copy not returning expected output
我有这个简单的代码,我知道我一定犯了一些愚蠢的错误:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iterator>
using namespace std;
int main()
{
vector<string> coll{"one", "two", "two", "three", "four", "one"};
vector<string> col2(coll.size(), "");
unique_copy(coll.cbegin(), coll.cend(), col2.begin());
for(const auto& ele : col2)
cout<<" - "<<ele;
cout<<endl;
return 0;
}
输出 -- one - two - three - four - one -
我期待:-- one - two - three - four - -
我错过了什么?
编辑:正如aswer中指出的那样 - 该死的,我错过了unique_copy本身的定义。
是否有任何功能可以做我期望的ecd(删除唯一元素,无论邻接关系如何),而不是将它们插入ordered set
或在唯一副本之前排序,因为我想保持排序。
std::unique_copy :
将元素从范围
[first, last)
复制到从d_first
开始的另一个范围,这样就没有连续的相等元素。
在您的情况下,one
不是连续的。
尝试:
vector<string> coll{"one", "one", "two", "two", "three", "four"};
你会发现输出为
- one - two - three - four - -
相关文章:
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- 返回 str vs. str.substr(0,str.size()) 在 leetcode 中给了我不同的输出
- C++输出参数与返回值
- cpp 返回具有相同输入的不同输出
- 显示C++输出而不返回值
- 简单函数并不总是返回预期的输出
- 输出返回编号。等于输入字符串的单词的字符串数
- 如何在C++中执行命令并获取命令的返回代码标准输出和标准
- 我的动态链接队列在同一输出流中调用时不正确地输出三个返回函数
- 为什么 boost::locale::to_title 不返回预期的输出?
- 在函数中连接两个字符,并在 C++ 中返回输出
- 同一个程序每次返回不同的输出
- C++如果使用 lambda 表达式的语句返回 true,但输出来自 false,为什么
- cout.width和cout.fill返回不同的输出
- C 输出返回值
- 面向对象C++帮助?出于某种原因,对象变量的输出返回数值数组位置而不是实际值
- 调用一个方法会将输出返回到同一类c++的另一个方法中
- 二进制文件中结构的输出返回垃圾
- KissFFT输出返回一个值
- 为什么FFTW输入非零,输出返回全零(c++)