code_junkie

c++ integer->std::string conversion. Simple function?

Nov 12th, 2011
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. std::string intToString(int i)
  2. {
  3. std::stringstream ss;
  4. std::string s;
  5. ss << i;
  6. s = ss.str();
  7.  
  8. return s;
  9. }
  10.  
  11. template<class T>
  12. std::string t_to_string(T i)
  13. {
  14. std::stringstream ss;
  15. std::string s;
  16. ss << i;
  17. s = ss.str();
  18.  
  19. return s;
  20. }
  21.  
  22. std::string s = t_to_string(my_integer);
  23.  
  24. std::string s = boost::lexical_cast<std::string>(i);
  25.  
  26. try{
  27. std::string s = boost::lexical_cast<std::string>(i);
  28. }catch(boost::bad_lexical_cast &){
  29. ...
  30. }
Add Comment
Please, Sign In to add comment