source: tags/1.0/tofromstring.h @ 5

Last change on this file since 5 was 5, checked in by willem, 11 years ago

willem

File size: 446 bytes
RevLine 
[5]1#include <sstream>
2#include <iomanip>
3template <class T>
4inline std::string to_string (const T& t)
5{
6  std::stringstream ss;
7  ss << t;
8  return ss.str();
9}
10template <class T>
11inline std::string to_string (const T& t,int w)
12{
13  std::stringstream ss;
14  ss << std::setfill('0') << std::setw(w) << t;
15  return ss.str();
16}
17template <class T>
18inline T from_string (std::string t)
19{
20  std::stringstream ss;
21  ss.str(t);
22  T x;
23  ss >> x;
24  return x;
25}
Note: See TracBrowser for help on using the repository browser.