CHAPTER4-4.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER4-4.cpp
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <iterator>
- using namespace std;
- template <class ForwardIterator, class T>
- void iota_n (ForwardIterator first, int n, T value)
- { for (int i = 0; i < n; i++) *first++ = value++;}
- main (int argc, char *argv[])
- {
- int n = 2; // argument checking removed for clarity
- vector<int> v;
- v.reserve(3);
- iota_n (v.begin(), n, 100);
- random_shuffle (v.begin(), v.end()); // shuffle
- copy (v.begin(), v.end(), ostream_iterator<int> (cout, "n")); // print
- }