User define iostream manipulators with parameters
-
I have been trying to write a function in VC++ 6.0 on setting the setprecision and setw in a function. This is roughly how I intend to do .. my_set_function(int precision,int width) { setprecision(precision); setwidth(width); } fstream io("abc.dat",ios::out); . . double abc=1.234566,bcd=2.3456; . io << my_set_function(3,5) << abc << my_set_function(2,4) << bcd; Since I want to set it for every variable, I hope to do it in a neater and shorter manner.I know this code is not a functional one , hope someone have some idea of what I am trying to do? THanks a million! :omg:
-
I have been trying to write a function in VC++ 6.0 on setting the setprecision and setw in a function. This is roughly how I intend to do .. my_set_function(int precision,int width) { setprecision(precision); setwidth(width); } fstream io("abc.dat",ios::out); . . double abc=1.234566,bcd=2.3456; . io << my_set_function(3,5) << abc << my_set_function(2,4) << bcd; Since I want to set it for every variable, I hope to do it in a neater and shorter manner.I know this code is not a functional one , hope someone have some idea of what I am trying to do? THanks a million! :omg:
If you want to write a manipulator that works for all types, including those that you did not define, then you'll need it to work in tandem with a stream of your own writing, which can very well be simply a stream that uses a normal stream, but applies your manipulator. Read my articles here on CP in the STL section for info on parameters in manipulators, and writing custom streams. Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002