Tranvick

Example18

Jan 8th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. //Пример 18. Потоковые классы:
  2. //манипуляторы; проектирование собственных манипуляторов
  3.  
  4. #include <iostream>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. class MM
  10. {   public:
  11.     int n,m;
  12.     ostream& (*f) (ostream&,int,int);
  13.  
  14.     MM(ostream& (*F) (ostream& ,int,int),int N,int M):f(F),n(N),m(M){}
  15. };
  16.  
  17.  ostream& operator<<(ostream& o, MM& mm)
  18.     {return mm.f(o, mm.n, mm.m);}
  19.  
  20.  
  21. ostream& format(ostream& o,int a,int b)
  22.     {o.width(a);  o.fill('=');  o.precision(b);
  23.      return o;
  24.     }
  25.  
  26. MM fMM(int n, int m){return MM(format,n,m);}
  27.  
  28. int main() {
  29.     double              d = 1.4785234;
  30.     double              d1 = 1.4785234e+10;
  31.     cout << "d=" << d << endl;
  32.     cout << "d1=" << d1 << endl;
  33.     cout << setiosflags( ios::showpos | ios::internal )
  34.     << setprecision( 2 ) << "d=" << setw( 15 ) << d << endl;
  35.     cout << setiosflags( ios::scientific ) << "d=" <<
  36.          setw( 15 ) << d << endl;
  37.     cout << resetiosflags( ios::internal ) <<
  38.       setiosflags( ios::left ) << setfill( '.' ) << "d1="
  39.          << setw( 15 ) << d1 << endl << endl;
  40.     cout<<fMM(15,10)<<5.0123456<<endl;
  41.      return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment