• check if a state is ok

    while(cin >> word)
    // ok: read successful

  • condition states are constants defined in ios_base as public members
    • ios_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 and badbit is set when an error occured during an input operation.
    • Failing to read due to reaching the end-of-file sets both eofbit and failbit.
    • fail() is a synonym of ios::operator!
  • checks
    • s.bad() : eofbit is set.
    • s.fail() : failbit or badbit 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
  • about types:
    • std::ios_base::iostate is type for stream error state flags

References:

  1. http://www.cplusplus.com/reference/ios/ios/fail/
  2. http://www.cplusplus.com/reference/ios/ios/operator_not/
  3. http://stackoverflow.com/questions/6255339/checking-if-a-file-opened-successfully-with-ifstream
  4. http://www.cplusplus.com/forum/beginner/6033/
  5. http://www.cplusplus.com/doc/tutorial/files/

right way check file open and end的更多相关文章

  1. 电脑每次开机都出现check file system on:C 的解决办法

    电脑每次开机都出现check file system on:C 的解决办法... ----------------------------------------- ----------------- ...

  2. windows安装dcm4chee 出错 check file system group LOSSY_STORAGE for deletion

    错误情景: 解决方法: 更改服务的监听端口(参考DICOM:Ubuntu14环境下安装dcm4chee+oviyam2.1)

  3. 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, ...

  4. 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 ...

  5. error_Could not load file or assembly

    原文链接 Could you be missing the loaded assembly from your configuration file? Ensure you have somethin ...

  6. udev example -- detect usb and write test file

    之前学习了下Udev,就随便做了个测试小程序.....设计什么的也没考虑,就实现了一个基本功能,插入U盘,识别,循环检测到有特定文件后,就然后往U盘里面写数据,插拔多次,都能正常工作. 里面的warn ...

  7. 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 ...

  8. 使用Monit监控本地进程

    目前用它监控某些服务,失败自动重启,同时监控特定的日志文件,如果有变化,就发邮件报警 安装不细写了,网上好多 我先用cat /proc/version看了下我的系统是el6的,于是wget http: ...

  9. SSD框架训练自己的数据集

    SSD demo中详细介绍了如何在VOC数据集上使用SSD进行物体检测的训练和验证.本文介绍如何使用SSD实现对自己数据集的训练和验证过程,内容包括: 1 数据集的标注2 数据集的转换3 使用SSD如 ...

随机推荐

  1. HDU 4612 (13年多校第二场1002)无向图缩点,有重边

    这道题是多校的题,比赛的时候是一道纷纷水过的板刷题. 题意:给你一些无向边,只加一条边,使该图的桥最少,然后输出最少的桥. 思路:当时大致想到思路了,就是缩点之后找出最长的链,然后用总的桥数减去链上的 ...

  2. Log4net从下载到使用例子

    一.首先下载log4net.dll   http://pan.baidu.com/s/1gdigrwJ 二.添加log4net引用 三.代码: using System; using System.C ...

  3. iOS高仿城觅-感谢大神分享

    项目展示,由于没有数据,所以所有的cell显示的都是我自己写的数据 抽屉 首页部分效果 首页效果 部分效果 发现 消息 搜索 设置 模糊效果 代码注释展示 代码注释展示 还有很多细节就不一一展示了,大 ...

  4. TypeError: not enough arguments for format string

    到一个问题,表示100% 的时候,出现这个问题. 因为python语法会认为是你需要转移符,这个时候你可以选择100%% 来表示

  5. Keil 中关于C语言编译生成汇编代码函数名规则

    在keil 中 C语言的函数有带参数和不带参数之分. 一般的资料里说fun(void)类型的函数不带参数,所以,keil编译器生成的汇编的调用地址(函数名) 为fun.这没有错.事实上,不管C语言的函 ...

  6. Qemu对x86静态内存布局的模拟

    快乐虾 http://blog.csdn.net/lights_joy/ lights@hb165.com 本文适用于 QEMU-0.10.5 VS2008 欢迎转载,但请保留作者信息 在PC机中,由 ...

  7. Android 中的接口回调

    http://blog.csdn.net/wangjinyu501/article/details/22052187   在Android中到处可见接口回调机制,尤其是UI事件处理方面.举一个最常见的 ...

  8. c++ 03

    一.面向对象编程 1.什么是对象?什么是对象编程? 1)万物皆对象 2)世界是由一组相互之间紧密联系的对象组成的. 3)通过将对象按照属性和行为共性进行分类,达到将具体事物进行抽象的效果. 4)通过程 ...

  9. 在CDHtmlDialog中处理WindowClosing

    要截获window.close(),就得截获CDHtmlDialog的WindowClosing.以下是示例代码: // header DECLARE_EVENTSINK_MAP() void Win ...

  10. mysql的日志

    是否启用了日志mysql>show variables like ‘log_bin’; 怎样知道当前的日志mysql> show master status; 看二进制日志文件用mysql ...