template <class OutputIterator, class Diff, class Generator> void generate_n( OutputIterator xFirst, Diff xCount, Generator xGenerator );
#include <algorithm>
#include <iostream> #include <vector> #include <algorithm> char Generate() { return (char)((rand() % 26) + 'a'); } int main() { using namespace std; // Create a vector instance vector<char> qV; qV.push_back('X'); qV.push_back('o'); qV.push_back('a'); qV.push_back('X'); qV.push_back('.'); qV.push_back('n'); qV.push_back('e'); qV.push_back('t'); vector<char>::iterator qIter; // Output the vector cout << "Original: "; for (qIter = qV.begin(); qIter != qV.end(); ++qIter) { cout << *qIter; } cout << endl; // Generate values for the last four entries generate_n(qV.begin() + 4, 4, Generate); // Output the vector after generating char values cout << "Generated: "; for (qIter = qV.begin(); qIter != qV.end(); ++qIter) { cout << *qIter; } cout << endl; // Keep the window open cin.get(); return 0; }
© 20072024 XoaX.net LLC. All rights reserved.