fork download
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4.  
  5. vector<float> MatMult(int a, vector<float> & b)
  6. {
  7. vector<float> c;
  8. int i;
  9. for(i=0;i<=b.size()-1;i++){
  10. c.at(i)=b.at(i)*a;
  11. }
  12. return c;
  13.  
  14. }
  15.  
  16. int main()
  17.  
  18.  
  19. {int a=3;
  20. vector<float> b{1,2,3,4,5};
  21. vector<float> c = MatMult(a,b);
  22. cout<<c[2];
  23. }
Runtime error #stdin #stdout #stderr 0s 3452KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)