Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

string_conversion.h

Go to the documentation of this file.
00001 # ifndef HepUtilities_string_conversion_h__included__
00002 # define HepUtilities_string_conversion_h__included__
00003 
00004 /*
00005  * \file
00006  *
00007  * converstions between std::string and any streamable type
00008  * using operators << and >>
00009  *
00010  * \author Jakub T. Moscicki, CERN 2001
00011  */
00012 
00013 # include <string>
00014 #ifdef OLDSTREAMS
00015 # include <strstream>
00016 # define ostringstream ostrstream
00017 # define istringstream istrstream
00018 #else
00019 # include <sstream>
00020 #endif
00021 
00022 namespace Anaphe
00023 {
00024 
00030 template<class T>
00031 std::string to_string(const T& val)
00032 {
00033   std::ostringstream buf;
00034 
00035   buf << val;
00036 #ifndef BADENDS
00037   buf << std::ends;
00038 #endif
00039   std::string ret = buf.str();
00040   return ret;
00041 }
00042 
00048 template<class T>
00049 bool to_value(std::string s, T& val)
00050 {
00051   std::istringstream buf(s.c_str());
00052   buf >> std::ws;
00053   return buf >> val;
00054 }
00055 
00056 }
00057 
00058 
00059 # endif

Generated on Tue May 20 14:50:25 2003 for HepUtilities by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002