#ifndef ROMANH #define ROMANH #include #include //for num_put #include //for basic_string, basic_ostringstream #include //for ostream_iterator #include //for fill_n, copy using namespace std; template > class basic_roman_put: public num_put { typedef typename num_put::iter_type iter_type; typedef typename num_put::char_type char_type; iter_type do_put(iter_type it, ios_base& b, char_type fill, long val) const; public: explicit basic_roman_put(size_t r = 0): num_put(r) {} }; typedef basic_roman_put roman_put; template typename basic_roman_put::iter_type basic_roman_put::do_put(iter_type it, ios_base& b, char_type fill, long val) const { //Generate a simplified Roman numeral. basic_ostringstream ost; const ios_base::fmtflags flags = b.flags(); const char_type c = flags & ios_base::uppercase ? 'I' : 'i'; fill_n(ostream_iterator(ost), val, c); //Generate the filling. basic_ostringstream ost2; ost2.flags(b.flags()); //Copy b's flags into ost2 (left justify, etc). ost2 << setfill(fill) << setw(b.width()) << ost.str(); b.width(0); //Make the width evaporate after its one use. //Copy the Roman numeral and its padding //into the container to which the output iterator it refers. const basic_string& s = ost2.str(); return copy(s.begin(), s.end(), it); } #endif