Advertisement
andruhovski

STL Genertate Demo

Feb 18th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <vector>
  6. #include <algorithm>
  7. #include <iostream>
  8. #include <iomanip>
  9.  
  10. using namespace std;
  11.  
  12. int fib()
  13. {
  14.     static int a = 0;
  15.     static int b = 1;
  16.     int s = a + b;
  17.     a = b;
  18.     return b = s;
  19. }
  20.  
  21. int _tmain(int argc, _TCHAR* argv[])
  22. {
  23.     vector<int> a(10);
  24.     generate(a.begin(), a.end(), fib);
  25.     for (auto x:a)
  26.     {
  27.         cout << setw(4) << x << endl;
  28.     }
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement