fork download
  1. #include <iostream>
  2. #include <iterator>
  3.  
  4.  
  5. template<typename InputIterator, typename OutputIterator>
  6. OutputIterator copy_odd(InputIterator first, InputIterator const last, OutputIterator out) {
  7. for ( ; first != last; ++first) {
  8. if (*first % 2 == 1) {
  9. *out = *first;
  10. }
  11. }
  12.  
  13. return out;
  14. }
  15.  
  16.  
  17. int main() {
  18. copy_odd(
  19. std::istream_iterator<int>(std::cin), std::istream_iterator<int>()
  20. , std::ostream_iterator<int>(std::cout, " "));
  21. }
Success #stdin #stdout 0s 3344KB
stdin
1 2 3 4 5 6 7 8
stdout
1 3 5 7