source: trunk/tofromstring.h

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

willem

File size: 1.0 KB
Line 
1
2/*
3   Copyright 2012 Willem Vermin, SARA
4
5   Licensed under the Apache License, Version 2.0 (the "License");
6   you may not use this file except in compliance with the License.
7   You may obtain a copy of the License at
8
9       http://www.apache.org/licenses/LICENSE-2.0
10
11   Unless required by applicable law or agreed to in writing, software
12   distributed under the License is distributed on an "AS IS" BASIS,
13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   See the License for the specific language governing permissions and
15   limitations under the License.
16 */
17
18#include <sstream>
19#include <iomanip>
20template <class T>
21inline std::string to_string (const T& t)
22{
23  std::stringstream ss;
24  ss << t;
25  return ss.str();
26}
27template <class T>
28inline std::string to_string (const T& t,int w)
29{
30  std::stringstream ss;
31  ss << std::setfill('0') << std::setw(w) << t;
32  return ss.str();
33}
34template <class T>
35inline T from_string (std::string t)
36{
37  std::stringstream ss;
38  ss.str(t);
39  T x;
40  ss >> x;
41  return x;
42}
Note: See TracBrowser for help on using the repository browser.