fork download
  1. #include<iostream>
  2. #include<string>
  3. #include<sstream>
  4.  
  5. template<typename ostringstream, typename T>
  6. std::string my_to_string (T&& value)
  7. {
  8. ostringstream oss;
  9. oss << value;
  10. return oss.str();
  11. }
  12.  
  13. #define my_to_string(X) my_to_string<std::ostringstream>(X)
  14.  
  15. #include<sstream>
  16.  
  17. int main ()
  18. {
  19. double d = 1.2345;
  20. std::string s = my_to_string(d);
  21. std::cout << "converted: " << s << "\n";
  22. }
  23.  
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
converted: 1.2345