IO对象不可复制或赋值。形参或返回类型不能为流类型。如果需要传递或返回IO对象,则必须传递或返回指向该对象的指针或引用。
ofstream &print(ofstream&); //ok:take a reference, no copy
while (print(out2)) { /*.....*/ } //ok:pass reference to out2
输出缓冲区的刷新
cout<< "hi!" << flush; //flushes the buffer; add no data
cout<< "hi!" << ends; //inserts a null, then flushes the buffer
cout<< "hi!" << endl; //inserts a newline, then flushes the buffer
cout<< unitbuf << "first" << "second" <<nounitbuf;
cout<< "first" << flush << "second" << flush; //等价
如果程序员需要重用文件流读写多个文件,必须在读另一个文件之前调用clear清除该流的状态。
第8章 标准IO库
最新推荐文章于 2022-05-05 19:11:49 发布