-
new fstream class
I am starting to write my own Non-STL fstream class because it is not supported by the compiler I'm using ( eVC++ 3.0). I looked at STLPort, but it is just too complex for what I really need. I have all the basic functionality working -- e.g. read, write in both binary and text modes. Now I want to start adding some of the more sophicated stuff, like setw() and setfill(). But I'm stuck on how to imnplement them. For example:
stream << setw(8) << setfill('*') << 123.45F << endl;
Can anyone tell me how setw and setfill functions are implemented so that they return the stream object?
Thanks
-
I think the best approach would be for you to look at a current
implementation if you don't want to use a library that's already
out there. So, look at STLPort's implementation of fstream and
find out how THEY do it. If you have Visual Studio, see how they
do it as well.
The more you imitate these, however, the stronger the argument
is for you to juse use STLPort [or some other library] to begin
with.
--Paul
-
Check out The C++ Programming Language by Bjarne Stroustrup. There's a whole section on how to write your own I/O manipulators (section 21.4.6.3).