Q:

Update the program from the previous exercise so that it prints only the unique elements. Your program should use unqiue_copy (§ 10.4.1, p. 403)

0

Update the program from the previous exercise so that it prints only the unique elements. Your program should use unqiue_copy (§ 10.4.1, p. 403).

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

int main() {
  std::istream_iterator<int> i_iter(std::cin), i_eof;
  std::vector<int> vi(i_iter, i_eof);
  std::sort(vi.begin(), vi.end());
  std::ostream_iterator<int> o_iter(std::cout, " ");
  std::unique_copy(vi.begin(), vi.end(), o_iter);

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now