iostream的一个例子
程序:
#include<string> using namespace std; string isbn; unsigned units_sold; double revenue; istream& input(istream& in) { in>>isbn>>units_sold>>revenue; if(in) cout<<"isbn:"<<isbn<<endl; cout<<"units_sold:"<<units_sold<<endl; cout<<"revenue:"<<revenue<<endl; } ostream& output(ostream& out) { out<<isbn<<" "
<<units_sold<<" "
<<revenue<<endl; } int main() { input(cin); output(cout); }
输入:HarryPott
10
18.8
输出:isbn:HarryPott
units_sold:10
revenue:18.8
harry 10 18.8