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_baseas 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
failbitandbadbitis set when an error occured during an input operation. - Failing to read due to reaching the end-of-file sets both
eofbitandfailbit. fail()is a synonym ofios::operator!
- At least one of
- checks
s.bad():eofbitis set.s.fail():failbitorbadbitis set.s.eof():eofis 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::iostateis 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如 ...
随机推荐
- css之自动换行-设计师零张
自动换行问题,正常字符的换行是比较合理的,而连续的数字和英文字符常常将容器撑大,挺让人头疼,下面介绍的是CSS如何实现换行的方法 对于div,p等块级元素 正常文字的换行(亚洲文字和非亚洲文字)元素拥 ...
- 多路查找树之2-3-4树和B树 - 数据结构和算法82
多路查找树之2-3-4树和B树 让编程改变世界 Change the world by program 由2-3树到2-3-4树 ...... 省略,具体请看视频讲解 ...... B树 一个m阶的B ...
- 基于zigbee与tiny4412开发板的环境监测系统
一.开发板环境搭建 1.tiny4412 linux系统的布置 参考博客:http://www.cnblogs.com/luoxiang/p/4186391.html 二.boa服务器的搭建 下载 ...
- .net 既可以输入又可以选择的dropdownlist
第一.<script src="../../../Common/Scripts/combox.js" type="text/javascript"> ...
- Qt Creator快捷键大全,附快捷键配置方法
一.快捷键配置方法: 进入“工具->选项->环境->键盘”即可配置快捷键. 二.常用默认快捷键: 编号 快捷键 功能 1 Esc 切换到代码编辑状态 2 F1 查看帮助( ...
- 通过jstack定位在线运行java系统故障_案例1
问题描述: 在一个在线运行的java web系统中,会定时运行一个FTP上传的任务,结果有一天发现,文件正常生成后却没有上传. 问题初步分析: 1.查看日志文件 发现这个任务只打印了开始进入FTP处理 ...
- 方案:解决 wordpress 中 gravatar 头像被墙问题
Gravatar头像具有很好的通用性,但是却遭到了无辜的拦截,对于无法加载头像URL,我们在WordPress系统中通过修改默认的URL链接可以达到恢复头像的功能. 修改文件路径为 /wp-inclu ...
- Hdu3714-Error Curves(三分)
Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...
- mysql基本介绍
RDBMS:1.数据库创建.删除除2.创建表.删除表.修改表3.索引的创建.删除4.用户和权限5.数据增.删.改6.查询 DML:Data Manapulate Language: 数据操作语言 ...
- python之路-模块 splinter
Splinter介绍 Splinter is an open source tool for testing web applications using Python. It lets you au ...