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

tostring.h

Go to the documentation of this file.
00001 #ifndef DV_THREAD_TOSTRING_H 00002 #define DV_THREAD_TOSTRING_H 00003 // $Id: tostring.h,v 1.6 2002/10/18 13:17:18 dvermeir Exp $ 00004 #include <string> 00005 #include <sstream> // for ostringstream 00006 00007 namespace Dv { 00008 namespace Util { 00009 /** 00010 * A function that converts anything that can be written to 00011 * a stream to a string (using the ostringstream class). 00012 * 00013 * 00014 * \param t object for which a string representation is sought. 00015 * \return a string representation of t. 00016 */ 00017 template<typename T> 00018 std::string tostring(const T& t) { 00019 std::ostringstream oss; 00020 oss << t; 00021 return oss.str(); 00022 } 00023 00024 /** 00025 * A function that converts anything that can be read from 00026 * a stream to a string (using the istringstream class). 00027 * 00028 * 00029 * \param t object for which a string representation is sought. 00030 * \param s string representation from which <code>t</code> is to be computed 00031 * \return true iff success 00032 */ 00033 template<typename T> 00034 bool 00035 fromstring(T& t, const std::string& s) { 00036 std::istringstream iss(s); 00037 return bool(iss >> t); 00038 } 00039 00040 }} 00041 #endif

dvutil-0.13.15 [30 December, 2004]