right way check file open and end
check if a state is ok
while(cin >> word)
// ok: read successful- condition states are constants defined in
ios_base
as public membersios_base::badbit
: corrupted.- set when the error involves the loss of integrity of the stream, which is likely to persist even if a different operation is attempted on the stream.
- indicates a system-level failure, such as an unrecoverable read or write error.
- usually not possible to use a stream once badbit has been set.
ios_base::failbit
: failed.- set by an operation when the error is related to the internal logic of the operation itself; further operations on the stream may be possible.
- is set after a recoverable error, such as reading a character when numeric data was expected.
- often possible to correct such problems and continue using the stream.
ios_base::eofbit
: hit end-of-file.ios_base::goodbit
: not in an error state.- indicating none of the other bits is set.
- Note
- At least one of
failbit
andbadbit
is set when an error occured during an input operation. - Failing to read due to reaching the end-of-file sets both
eofbit
andfailbit
. fail()
is a synonym ofios::operator!
- At least one of
- checks
s.bad()
:eofbit
is set.s.fail()
:failbit
orbadbit
is set.s.eof()
:eof
is set.s.good()
: none of above three states is set.s.is_open()
:s.clear()
: reset all condition values in the stream to valid state.
- operation on flags
- retrieve :
basic_ios::rdstate
- set :
basic_ios::setstate
- retrieve :
- about types:
std::ios_base::iostate
is type for stream error state flags
References:
- http://www.cplusplus.com/reference/ios/ios/fail/
- http://www.cplusplus.com/reference/ios/ios/operator_not/
- http://stackoverflow.com/questions/6255339/checking-if-a-file-opened-successfully-with-ifstream
- http://www.cplusplus.com/forum/beginner/6033/
- http://www.cplusplus.com/doc/tutorial/files/
right way check file open and end的更多相关文章
- 电脑每次开机都出现check file system on:C 的解决办法
电脑每次开机都出现check file system on:C 的解决办法... ----------------------------------------- ----------------- ...
- windows安装dcm4chee 出错 check file system group LOSSY_STORAGE for deletion
错误情景: 解决方法: 更改服务的监听端口(参考DICOM:Ubuntu14环境下安装dcm4chee+oviyam2.1)
- 12 Useful “df” Commands to Check Disk Space in Linux
On the internet you will find plenty of tools for checking disk space utilization in Linux. However, ...
- Analysis about different methods for reading and writing file in Java language
referee:Java Programming Tutorial Advanced Input & Output (I/O) JDK 1.4+ introduced the so-calle ...
- error_Could not load file or assembly
原文链接 Could you be missing the loaded assembly from your configuration file? Ensure you have somethin ...
- udev example -- detect usb and write test file
之前学习了下Udev,就随便做了个测试小程序.....设计什么的也没考虑,就实现了一个基本功能,插入U盘,识别,循环检测到有特定文件后,就然后往U盘里面写数据,插拔多次,都能正常工作. 里面的warn ...
- Fix Scheduled Task Won’t Run for .BAT File
Step 1: Check File/Folder Permissions The first step to fixing this issue is ensuring that the accou ...
- 使用Monit监控本地进程
目前用它监控某些服务,失败自动重启,同时监控特定的日志文件,如果有变化,就发邮件报警 安装不细写了,网上好多 我先用cat /proc/version看了下我的系统是el6的,于是wget http: ...
- SSD框架训练自己的数据集
SSD demo中详细介绍了如何在VOC数据集上使用SSD进行物体检测的训练和验证.本文介绍如何使用SSD实现对自己数据集的训练和验证过程,内容包括: 1 数据集的标注2 数据集的转换3 使用SSD如 ...
随机推荐
- The Time in Words
def main(): time = ["one", "two", "three", "four", "fiv ...
- js基础小总结之string&array&object
一.数据类型之间的转换 string--->number :parseInt(string)/parseFloat(string); 注:在Date中,因为返回值date为单位为ms的字符串,将 ...
- Log4net从下载到使用例子
一.首先下载log4net.dll http://pan.baidu.com/s/1gdigrwJ 二.添加log4net引用 三.代码: using System; using System.C ...
- Linux下使用sendmail发送邮件
现在每天需要将统计数据发送给指定的人员. 使用原始手工的方式每天发送很麻烦,于是想改成一个定时任务,让服务器自动发送. 技术告诉我说他有写过sendmail的一个脚本. 我尝试使用了一下,发现 ser ...
- ps存jpeg,格式保存的时候为什么选择“基线”
jpeg是印前和网页设计常用的格式,最大好处就是能很大程度上压缩图像大小. 在ps中将图片保存为jpeg格式的时候会出现以下选项: 其中:图像选项都很熟悉,是关于图像质量的:而格式选项的用途主要是针对 ...
- Honkly分享链接集总篇
VC6.0 Filetool Honkly版 http://pan.baidu.com/s/1bnentr5 密码:15eq,解压密码:honkly VC6.0 Filetool 官方 ...
- 自定义Filter服务
自定义一个用户Email长度超过12个字符后值截取前12个然后添加“...”显示. 例如: index.html <!DOCTYPE html> <html ng-app=" ...
- MVC4+Springnet+Nhibernate学习系列随笔(一)
Springnet与asp.net mvc4集成大体步骤 1.首先要在MVC项目中引用的两个程序集(Spring.Web与Spring.Web.Mvc4) 集 2.修改MVC项目的Global.asa ...
- 2015第15周日PostgreSQL学习
英文版官网地址:http://www.postgresql.org/ 上面显示的最新版本信息是PostgreSQL 9.4.1, 9.3.6, 9.2.10, 9.1.15 & 9.0.19 ...
- Inorder Successor in BST 解答
Question Given a binary search tree and a node in it, find the in-order successor of that node in th ...