IO Streams and Recursion

IO Streams and Recursion - Lecture 6a: Review of Streams,...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 6a: Review of Streams, File I/O and Recursions CS256 – Fall 2008
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
I/O stream Stream A flow of data objects Input stream and output stream I/O streams defined in <iostream> cin and cout: keyboard and screen File I/O Practiced in Lab #2 <fstream> ifstream and ofstream
Background image of page 2
File I/O File names External file names such as “test1.txt” Internal file names, name of file streams ifstream fin; ofstream fout; Steps for file processing Declaration Open/create files (e.g. fin.open(“test1.txt”);) Read/write from/to files (e.g. fin >> data; fout<<data;) Close files (e.g. fin.close(); fout.close();) Close of output stream automatically flushes the buffer Or you may call fout.flush() to flush the buffer
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Opening Files Opening input file e.g. fin.open(“test.txt”); or ifstream fin (“test.txt”); Creating output file e.g. fout.open(“result.txt”); or ofstream fout(“result.txt”); Appending to output file e.g. fout.open(“result.txt”, ios:app); or ofstream fout(“result.txt”, ios:app);
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

IO Streams and Recursion - Lecture 6a: Review of Streams,...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online