Use exceptions to watch for and handle I/O errors.
来源:互联网 发布:老虎证券 客户端软件 编辑:程序博客网 时间:2024/05/17 06:34
#include <iostream>#include <fstream>#include <cstring>using namespace std;struct inventory { char item[20]; int quantity; double cost;};int main(){ int completion_status = 0; ofstream fout; fout.exceptions(ios::failbit | ios::badbit); try { fout.open("InvDat.dat", ios::out | ios::binary); } catch(ios_base::failure exc) { cout << "Cannot open file.\n"; cout << "String returned by what(): " << exc.what() << endl; return 1; } inventory inv[3]; strcpy(inv[0].item,"A"); inv[0].quantity = 1; inv[0].cost = 9.9; strcpy(inv[1].item, "B"); inv[1].quantity = 2; inv[1].cost = 7.5; strcpy(inv[2].item, "C"); inv[2].quantity = 19; inv[2].cost = 2.75; try { for(int i=0; i<3; i++) fout.write((const char *) &inv[i], sizeof(inventory)); } catch(ios_base::failure exc) { cout << exc.what() << endl; completion_status = 1; } try { fout.close(); } catch(ios_base::failure exc) { cout << exc.what() << endl; completion_status = 1; } return completion_status;
- Use exceptions to watch for and handle I/O errors.
- Use exceptions to watch for and handle I/O errors.
- Errors and Exceptions
- Python Errors and Exceptions
- Python Errors and Exceptions
- Item 58: Used checked exceptions for recoverable conditions and runtime exceptions for programming errors
- How to: Handle Data Conflicts and Errors 【转载】
- Bash Commands - the diff of > and >> # Use I/O Redirection to generate a log file
- How to use iPhone with File I/O Functions: A Tutorial for Software Developers
- How to use iPhone with File I/O Functions: A Tutorial for Software Developers
- Use UIGestureRecognizer to handle single tap and double tap
- Errors in file : ORA-27091: unable to queue I/O
- Files and Exceptions: Dealing with Errors
- [python3教程]第八章.ERRORS AND EXCEPTIONS
- I need to learn ARM assembly, and I use Linux.
- Getting your driver to handle more than one I/O request
- initrd, initramfs, which I need and how to use???
- python tutorial 学习笔记(七)Errors and Exceptions
- 我的汇编笔记
- WordPress中自动获取文章中的图片
- 11-28 自己写一个数据集DataSet---ds,向其中添加一个数据表DataTable ---dt,并创建该表的列和行。然后将本本表作为数据源绑定到GradView中。
- 经典的机器学习方面源代码库
- C#提高知识 ADO.NET实体数据模型 (2)
- Use exceptions to watch for and handle I/O errors.
- BinaryTree实现
- dedeCMS
- 【Oracle入门系列】第04章_函数
- 国内量化交易平台
- 连接池的运用
- 从团购中思索营销的新方式
- 深入体验JavaWeb开发内幕——Apache—DBUtils框架
- 利用SOLR搭建企业搜索平台 之四(MultiCore)