Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Пример 18. Потоковые классы:
- //манипуляторы; проектирование собственных манипуляторов
- #include <iostream>
- #include <iomanip>
- using namespace std;
- class MM
- { public:
- int n,m;
- ostream& (*f) (ostream&,int,int);
- MM(ostream& (*F) (ostream& ,int,int),int N,int M):f(F),n(N),m(M){}
- };
- ostream& operator<<(ostream& o, MM& mm)
- {return mm.f(o, mm.n, mm.m);}
- ostream& format(ostream& o,int a,int b)
- {o.width(a); o.fill('='); o.precision(b);
- return o;
- }
- MM fMM(int n, int m){return MM(format,n,m);}
- int main() {
- double d = 1.4785234;
- double d1 = 1.4785234e+10;
- cout << "d=" << d << endl;
- cout << "d1=" << d1 << endl;
- cout << setiosflags( ios::showpos | ios::internal )
- << setprecision( 2 ) << "d=" << setw( 15 ) << d << endl;
- cout << setiosflags( ios::scientific ) << "d=" <<
- setw( 15 ) << d << endl;
- cout << resetiosflags( ios::internal ) <<
- setiosflags( ios::left ) << setfill( '.' ) << "d1="
- << setw( 15 ) << d1 << endl << endl;
- cout<<fMM(15,10)<<5.0123456<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment