fstream的close与clear先后次序的问题

 

fstream::close:

 

Calls the close member function for the associated filebuf object. This function, in turn, flushes any waiting output, closes the file, and disconnects the file from the filebuf object. The filebuf object is not destroyed.

 

ios::clear

void clear( int nState = 0 );

Parameter

nState

If 0, all error bits are cleared; otherwise bits are set according to the following masks (ios enumerators) that can be combined using the bitwise OR ( | ) operator. The nState parameter must have one of the following values:

  • ios::goodbit   No error condition (no bits set).

  • ios::eofbit   End of file reached.

  • ios::failbit   A possibly recoverable formatting or conversion error.

  • ios::badbit   A severe I/O error.

Remarks

Sets or clears the error-state flags. The rdstate function can be used to read the current error state.

 

==========================================

 

在对文件流操作时,如果要对同一个流对象应用,一般是先close,后clear。

 

具体例子 refer to: http://topic.csdn.net/u/20080828/14/9dad65a7-bcf2-42e0-83fb-1820f03c8bed.html

             //c++ primer P253 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值