fork(4) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. template<typename T>
  6. std::string toString(const T& t) {
  7. return std::to_string(t);
  8. }
  9.  
  10. std::string toString(const char* t) {
  11. return t;
  12. }
  13.  
  14. std::string toString(const std::string& t) {
  15. return t;
  16. }
  17.  
  18. int main() {
  19. cout << toString(10) << endl;
  20. cout << toString(1.5) << endl;
  21. cout << toString("char*") << endl;
  22. cout << toString(std::string("string")) << endl;
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
10
1.500000
char*
string