fork(1) download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <vector>
  4. #include <cstdint>
  5. #include <iterator>
  6. using namespace std;
  7.  
  8. template <class T> int getVector(istream& s,
  9. int32_t nbrCells,
  10. typename vector<T>::iterator iter)
  11. {
  12. int rc = 0;
  13. typename vector<T>::iterator save = iter;
  14.  
  15. if (s.flags() & ios::hex)
  16. {
  17. uint32_t utemp;
  18. while ((distance(save, iter) != nbrCells) && (s >> utemp))
  19. *iter++ = utemp;
  20. }
  21. else
  22. {
  23. int32_t temp;
  24. while ((distance(save, iter) != nbrCells) && (s >> temp))
  25. *iter++ = temp;
  26.  
  27. }
  28. return rc;
  29. }
  30. int main()
  31. {
  32. std::vector<int32_t> v(10);
  33. std::istringstream is("1 2 3 4 5\n6 7 8 9 10");
  34. const int32_t NCO=10;
  35. int rc = getVector<int32_t>(is, NCO, v.begin());
  36. copy(v.begin(), v.end(), std::ostream_iterator<int32_t>(std::cout, " "));
  37. std::cout << '\n';
  38. }
  39.  
Success #stdin #stdout 0s 2964KB
stdin
Standard input is empty
stdout
1 2 3 4 5 6 7 8 9 10