|
-
Jun 8th, 2004, 12:37 PM
#1
Thread Starter
Addicted Member
Manipulators
I've got a HTML-based Log class which I've designed to work in the same way as streams to allow for formatting. Now I want to have a manipulator similar to endl which will insert <BR> at the current position.
Can someone tell me how to code a manipulator like this?
Using Visual Studio .NET 2005
-
Jun 9th, 2004, 02:51 AM
#2
The typical stream manipulator is simply a function that takes a single argument, in its full versions:
Code:
// Flag manipulator
ios_base &name(ios_base &stream) {
// insertion/extraction action
return stream;
}
// State manipulator
template<typename C, typename T = std::char_traits<C> >
basic_ios<C, T> &name(basic_ios<C, T> &stream) {
return stream;
}
// Input manipulator
template<typename C, typename T = std::char_traits<C> >
basic_istream<C, T> &name(basic_istream<C, T> &stream) {
return stream;
}
// Output manipulator
template<typename C, typename T = std::char_traits<C> >
basic_ostream<C, T> &name(basic_ostream<C, T> &stream) {
return stream;
}
The << and >> operators are overloaded to allow such functions to be inserted, the operators then call the function.
Parametrized manipulators like setw are something different.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|