fork download
  1. // Lab 12 - STL vector
  2. // Programmer: Elaine Torrez
  3. // Class: CMPR 121
  4.  
  5. #include <iostream>
  6. #include <vector>
  7. using namespace std;
  8.  
  9. void showInfo(vector<int> numbers);
  10.  
  11. int main()
  12. {
  13. vector<int> numbers = {1, 3, 5, 7, 9};
  14.  
  15. showInfo(numbers);
  16.  
  17. return 0;
  18. }
  19.  
  20. void showInfo(vector<int> numbers)
  21. {
  22. numbers.pop_back();
  23.  
  24. cout << "There are " << numbers.size() << " values in the vector." << endl;
  25. cout << endl;
  26.  
  27. cout << "There are " << numbers.capacity() << " array elements in the vector." << endl;
  28. cout << endl;
  29.  
  30. cout << "The maximum number of int values the vector can hold is "
  31. << numbers.max_size() << "." << endl;
  32. cout << endl;
  33.  
  34. cout << "The value at the front is: " << numbers.front() << "." << endl;
  35. cout << endl;
  36.  
  37. cout << "The value at the back is: " << numbers.back() << "." << endl;
  38. cout << endl;
  39.  
  40. cout << "Here are all values in the vector:" << endl;
  41.  
  42. for (int index = 0; index < numbers.size(); index++)
  43. {
  44. cout << numbers[index] << endl;
  45. }
  46.  
  47. numbers.resize(2);
  48.  
  49. cout << "After resizing, there are " << numbers.size()
  50. << " values in the vector." << endl;
  51. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
There are 4 values in the vector.

There are 5 array elements in the vector.

The maximum number of int values the vector can hold is 4611686018427387903.

The value at the front is:  1.

The value at the back is:  7.

Here are all values in the vector:
1
3
5
7
After resizing, there are 2 values in the vector.