fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main() {
  5. std::vector<float> v{1,2,3,4,5};
  6.  
  7. // Output: 3
  8. std::cout << v.at(v.size()/2) << std::endl;
  9.  
  10. // Now a user provides another value, maybe
  11. v.push_back(6);
  12.  
  13. // Output: 4
  14. std::cout << v.at(v.size()/2) << std::endl;
  15. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
3
4