3 This file is part of libmspstrings
4 Copyright © 2006-2007 Mikko Rasa
5 Distributed under the LGPL
8 #ifndef MSP_STRINGS_LEXICALCAST_H_
9 #define MSP_STRINGS_LEXICALCAST_H_
13 #include <msp/core/except.h>
18 class LexicalError: public Exception
21 LexicalError(const std::string &w_): Exception(w_) { }
25 T lexical_cast(const std::string &s)
27 std::istringstream ss(s);
28 ss.setf(std::ios_base::fmtflags(0), std::ios_base::skipws);
33 if(ss.fail() || !ss.eof())
34 throw LexicalError("Conversion failure");
40 std::string lexical_cast(const T &v, const Fmt &f=Fmt())
42 std::ostringstream ss;