- //文件名:CHAPTER4-2.cpp
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <iterator>
- using namespace std;
- void main (int argc, char *argv[])
- {
- int n = 3; // argument checking removed for clarity
- vector<int> v;
- for (int i = 0; i < n; i++) // append integers 0 to n-1 to v
- v.push_back (i);
- random_shuffle (v.begin(), v.end()); // shuffle
- copy (v.begin(), v.end(), ostream_iterator<int> (cout, "n")); // print
- }