fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. std::vector<int> NumArray(int s)
  5. {
  6. std::vector<int> out;
  7. for(int n, i = 0; i < s; ++i)
  8. if(std::cin >> n)
  9. out.push_back(n);
  10. return out;
  11. }
  12.  
  13. const int size = 5;
  14.  
  15. int main()
  16. {
  17. std::cout << "Enter Values: \n";
  18. std::vector<int> values = NumArray(size);
  19. std::cout << "Values: ";
  20. for(int n: values)
  21. std::cout << n << ' ';
  22. std::cout << '\n';
  23. }
  24.  
Success #stdin #stdout 0s 2988KB
stdin
7 -1 20 3 4
stdout
Enter Values: 
Values: 7 -1 20 3 4