fork download
  1. #include <cstdarg>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. template <typename T>
  6. std::vector<T> initVector (int len, ...)
  7. {
  8. std::vector<T> v;
  9. va_list vl;
  10. va_start(vl, len);
  11. //v.push_back(va_arg(vl, T));
  12. for (int i = 0; i < len; ++i)
  13. v.push_back(va_arg(vl, T));
  14. va_end(vl);
  15. return v;
  16. }
  17.  
  18. int main ()
  19. {
  20. std::vector<int> v = initVector<int> (7,702,422,631,834,892,104,772);
  21. for(std::vector<int>::const_iterator it = v.begin() ; it != v.end(); ++it)
  22. std::cout << *it << std::endl;
  23. return 0;
  24. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
702
422
631
834
892
104
772