[ create a new paste ] login | about

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

aaronla - C++, pasted on Oct 2:
#include <iostream>
#include <iomanip>
#include <iterator>
#include <vector>
using namespace std;

int counting_numbers(){
  static int x = 0;
  return ++x;
}

int main(){
  vector<int> vec(5);
  generate(vec.begin(), vec.end(), counting_numbers);

  typedef vector<int>::const_iterator iter;
  for(iter a = vec.begin(); a != vec.end(); ++a){
    iter cur = a;
    unsigned i = 0;
    for(; cur != vec.end() && i < 3; ++cur, ++i){
        cout << *cur << " ";
    }
    cout << "\n";
  }
}


Output:
1
2
3
4
5
1 2 3 
2 3 4 
3 4 5 
4 5 
5 


Create a new paste based on this one


Comments: