{ int n,m;
ostream & (*f)(ostream&,int,int);
public:
manip(ostream& (*F)(ostream&,int,int), int N, int M):
f(F), n(N), m(M) {}
friend ostream& operator<<(ostream& s, const manip& obj)
{return obj.f(s,obj.n,obj.m);}
};
ostream& f_man(ostream & s,int n,int m)
{ s.width(n);
s.flags(ios::fixed);
s.precision(m);
return s;
}
manip wp(int n,int m)
{ return manip(f_man,n,m);
}
int main()
{ cout<< 2.3456 << endl;
cout<<wp(8,1)<<2.3456 << endl;
return 0;
}
- put
- ostream::put() :
char c=a;
...
cout.put(c);
put() :
cout.put(c).put('b').put('\n');
, b .
- get getline .
istream::get() .
. . , get EOF.
#include<iostream>
using namespace std;
int main()
{ char c;
cout << cin.eof()<< " " << endl;
while((c=cin.get())!=EOF)
cout.put(c);
cout << endl<<cin.eof();
return 0;
}
cin put. (Ctrl+z) while. , cin.eof(), false ( 0). true ( 1).
get() . false , − istream, get.
...
while(in.get())
cout.put(c);
...
get() : (), ( '\n'). , -. -. - , get .
har s[30];
...
in.get(s,20)) // cin.get(s,20, '\n')
cout<<s<<endl;
...
isteram::getline() get() , - .
- istream.