• Source
    1. #include <iostream>
    2. #include <vector>
    3. #include <bits/stdc++.h>
    4. using namespace std;
    5.  
    6. int main() {
    7. // your code goes here
    8. vector<int> temp;
    9. cout << "inserting elements in vectors" << endl;
    10. for( int i = 0; i < 3; i++ )
    11. {
    12. temp.push_back(i);
    13. }
    14.  
    15. // here we are using latest C++11 range based for loop
    16. // https://www.geeksforgeeks.org/range-based-loop-c/
    17. for( int count: temp )
    18. {
    19. cout << count << endl;
    20. }
    21.  
    22. cout << "using insert" << endl;
    23. temp.insert( temp.begin(), 10 );
    24. for( int count: temp )
    25. {
    26. cout << count << endl;
    27. }
    28.  
    29. cout << "using at" << endl;
    30. temp.at(0) = 111;
    31. for( int count: temp )
    32. {
    33. cout << count << endl;
    34. }
    35.  
    36. cout << "using []" << endl;
    37. temp[0] = 222;
    38. for( int count: temp )
    39. {
    40. cout << count << endl;
    41. }
    42.  
    43. auto it = find(temp.begin(), temp.end(), 2);
    44. if (it != temp.end())
    45. {
    46. int index = it - temp.begin();
    47. cout << "element found at" << index << endl;
    48. }
    49. else
    50. {
    51. cout << "element not found" << endl;
    52. }
    53.  
    54. return 0;
    55. }