fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <typeinfo>
  4.  
  5.  
  6. template<typename T>
  7. void printVector(const std::vector<T>& vect)
  8. {
  9. std::cout << std::endl << typeid(T).name() << ": " << std::endl;
  10. for(const auto& x: vect)
  11. std::cout << x << ' ';
  12. std::cout << std::endl;
  13. }
  14.  
  15. int main(int argc, char *argv[])
  16. {
  17. std::vector<int> v1{1,2,3,4,5,6,7,8,9,10};
  18. std::vector<double> v2{1.1,2.1,3.1,4.1,5.1,6.1,7.1,8.1,9.1,10.1};
  19. std::vector<char> v3{'a','b','c','d','e'};
  20. std::vector<std::string> v4{"foo", "bar", "lol"};
  21.  
  22. printVector(v1);
  23. printVector(v2);
  24. printVector(v3);
  25. printVector(v4);
  26. }
Success #stdin #stdout 0s 3236KB
stdin
Standard input is empty
stdout
i: 
1 2 3 4 5 6 7 8 9 10 

d: 
1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 9.1 10.1 

c: 
a b c d e 

Ss: 
foo bar lol