Use exceptions to watch for and handle I/O errors.
来源:互联网 发布:如何安装cad软件 编辑:程序博客网 时间:2024/05/16 17:20
#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
- POCO C++库导游
- draw9patch详解
- Ubuntu的debootstrap
- 完数
- C++实例之虚函数(析构函数和普通函数)
- Use exceptions to watch for and handle I/O errors.
- android_launcher的源码详细分析
- c# ref参数使用
- KMP算法
- 系统提示SVCHOST错误,该内存不能为“read”解决办法
- diff和patch使用指南
- Use eof() to read and display a text file.
- 请热爱c++(转自人人)
- bug满天飞的工作心得(2012.08.10)