- 0
- 0
- 约9.48千字
- 约 36页
- 2023-01-08 发布于贵州
- 举报
File Streams and File I/OChapter 12
Now a deeper look at StreamsWhat is a stream (in real life)?
Now a deeper look at StreamsWhat is a stream (in real life)?a flow of water from one place to another
Now a deeper look at StreamsWhat is a stream (in real life)?a flow of water from one place to anotheriostreams are the same concept, but are a flow of data from one point to another
Now a deeper look at StreamsWhat is a stream (in real life)?a flow of water from one place to anotheriostreams are the same concept, but are a flow of data from one point to anotheristream: bring information in (cin)ostream: take information out (cout)ifstream: bring information in from a fileofstream take information out to a file ifstream will have the same operations as istream ofstream will have the same operations as ostream
File Streams: fstreamSo what do we want to do with filesopen them for reading or writingread or write to themcheck if we have finished reading close them after using them
Opening a File Create a variable of ifstream or ofstreamUse the open functionifstream fin; // create the ifstream variablefin.open(“myfile.txt”); // tries to open the fileint i;fin i; // reading from the fileNote: myfile.txt will need to be in the same directory as where the program is running.
Opening a File Opening a ifstream variable tries to open an existing file read only modeOpening an ofstream variable opensa new file with the file name given by your programwrite only modeofstream fout; // create ofstream variablefout.open(“myfile.txt”); // tries to create the file
Checking to see if a file opened Two ways to check to see if a file is read for use:fail( ) function – returns true if not ready to readif ( fin == false ) – fstream variable will be equal to false if not readyifstream fin; // create the ifstream variablefin.open(“myfile.txt”); // tries to open the fileif ( fin.fail( ) ) { // check if file is ready // do something}
What can you do
您可能关注的文档
最近下载
- 2026最新施工资质挂靠协议.docx
- 美好前程-Vencorex.pdf VIP
- 传感器技术及应用中职课件完整全套教学课件.pptx VIP
- 机车动力装置检查与维修课件:16V265H型柴油机配气机构.pptx VIP
- 2026年度江苏财经职业技术学院单招《数学》检测卷AB卷附答案详解.docx VIP
- 《领略丝路遗珍》核心素养教学设计 2026人美版美术八年级下册.pdf
- 材料成形原理-第十章-偏析.ppt
- (2026年春季新版本)人教版三年级数学下册全册教案.docx
- API 682-2014 离心泵和转子泵用轴封系统 第四版(中文).pdf
- IPC-2221C-EN TOC2023印制版设计通用标准 Generic Standard on Printed Board Design.pdf VIP
原创力文档

文档评论(0)