1 // Uncomment this only is you are REALLY sure templates work on your system 2 //#define WANT_TEMPLATES 3 4 #ifndef ioformat_h 5 #define ioformat_h 6 7 //Convert to string 10/05/01 8 9 #include <iostream> 10 #include <string> 11 12 typedef std::ios_base::fmtflags opt_mode; 13 14 15 namespace OPTPP { 16 17 class oformatstate 18 { 19 public: 20 oformatstate(std::ostream& ut); 21 oformatstate (char code, int w=0, int p=0, char c=' ', opt_mode f = std::ios_base::fixed); 22 friend std::ostream& operator << (std::ostream& ut, oformatstate const& fmt); 23 friend std::ostream& operator >> (std::ostream& ut, oformatstate& fmt); 24 25 private: 26 int owidth; 27 int oprecision; 28 char ofill; 29 opt_mode oflags; 30 }; 31 32 std::string format(double val, oformatstate const& fmt); 33 std::string format(int val, oformatstate const& fmt); 34 35 inline std::string 36 d(int val, int w=0, int p=0, char c=' ', opt_mode f = std::ios_base::fixed) 37 { 38 oformatstate fmt('d', w, p, c, f); 39 return format(val, fmt); 40 } 41 inline std::string 42 e(double val, int w=0, int p=0, char c=' ', opt_mode f = std::ios_base::fixed) 43 { 44 oformatstate fmt('e', w, p, c, f); 45 return format(val, fmt); 46 } 47 inline std::string 48 f(double val, int w=0, int p=0, char c=' ', opt_mode f = std::ios_base::fixed) 49 { 50 oformatstate fmt('f', w, p, c, f); 51 return format(val, fmt); 52 } 53 54 } // namespace OPTPP 55 56 #endif 57