fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. vector<int> myvector;
  9. int myint;
  10. cout << "Please enter some integers (enter 0 to end):\n";
  11. for (int i=0; i<5; i++){
  12. cin >> myint;
  13. myvector.push_back (myint);
  14. }
  15.  
  16. cout << "myvector stores " << int(myvector.size()) << " numbers.\n";
  17. for (vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
  18. cout << ' ' << *it;\
  19. cout << endl;
  20. for (int i=0; i<5; i++){
  21. cout << myvector [i]; }
  22. cout << endl;
  23. myvector.pop_back();
  24. for (vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
  25. cout << ' ' << *it;\
  26. cout << endl;
  27. if(myvector.empty())
  28. cout << endl;
  29. cout << myvector.back();
  30. cout << endl;
  31. cout << myvector.front();
  32. cout << endl;
  33. sort (myvector.begin(), myvector.end());
  34. cout << endl;
  35. for (vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
  36. cout << ' ' << *it;\
  37. cout << endl;
  38.  
  39. cout << myvector.size();
  40. cout << endl;
  41. int searchValue;
  42. cout << "Enter a value to search for";
  43. cin >> searchValue;
  44. vector<int>::iterator it= find(myvector.begin(), myvector.end(), searchValue);
  45. if ( it == myvector.end() )
  46. cout << "Value found";
  47. else (cout << "Value is not found");
  48. cout << endl;
  49. myvector.clear();
  50. }
Success #stdin #stdout 0.01s 5292KB
stdin
9 1 7 5 3
9
stdout
Please enter some integers (enter 0 to end):
myvector stores 5 numbers.
 9 1 7 5 3
91753
 9 1 7 5
5
9

 1 5 7 9
4
Enter a value to search forValue is not found