[ create a new paste ] login | about

Link: http://codepad.org/oYqPiMej    [ raw code | output | fork ]

C++, pasted on Feb 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
struct ostream_write_int : std::iterator<std::output_iterator_tag, int, void, void, void> {
  std::ostream *s;
  ostream_write_int(std::ostream &s) : s (&s) {}

  ostream_write_int& operator++() { return *this; }
  ostream_write_int& operator++(int) { return *this; }
  ostream_write_int& operator*() { return *this; }
  void operator=(int x) {
    s->write(reinterpret_cast<char*>(&x), sizeof(x));
  }
};

int main() {
  vector<int> v (1, 0x41424344);
  copy(v.begin(), v.end(), ostream_write_int(cout));
}


Output:
1
DCBA


Create a new paste based on this one


Comments: