|
|
1.1 root 1: // exios202.cpp
2: // A custom manipulator with a char* parameter
3: #include <iostream.h>
4:
5: #include <iomanip.h>
6: #include <string.h>
7:
8: typedef char* charp;
9: IOMANIPdeclare( charp );
10:
11: class money {
12: private:
13: long value;
14: static char *szCurrentPic;
15: public:
16: money( long val ) { value = val; }
17: friend ostream& operator << ( ostream& os, money m ) {
18: // A more complete function would merge the picture
19: // with the value rather than simply appending it
20: os << m.value << '[' << money::szCurrentPic << ']';
21: return os;
22: }
23: friend ostream& setpic( ostream& os, char* szPic ) {
24: money::szCurrentPic = new char[strlen( szPic ) + 1];
25: strcpy( money::szCurrentPic, szPic );
26: return os;
27: }
28: };
29: char *money::szCurrentPic; // Static pointer to picture
30:
31: OMANIP(charp) setpic(charp c)
32: {
33: return OMANIP(charp) (setpic, c);
34: }
35:
36: void main()
37: {
38: money amt = 35235.22;
39: cout << setiosflags( ios::fixed );
40: cout << setpic( "###,###,###.##" ) << "amount = " << amt << endl;
41: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.