
Understanding Files, Streams, and Input/Output Operations
Explore the fundamentals of files, memory hierarchy, file properties, and stream classes in C++. Learn how to manipulate data through console and file input/output operations using streams in programming. Enhance your knowledge of handling secondary storage data efficiently.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
INTRODUCTION TO FILES AND STREAMS File I/O Delroy A. Brinkerhoff
MEMORY HIERARCHY Registers are part of the CPU Accessible with assembly code but not C++ Main/Primary/RAM is where variables live Mass/Secondary is the topic of this chapter
FILES A file is a named collection of related information that is recorded on secondary storage. A file is the smallest allotment of logical secondary storage; the OS can only store data in secondary storage as a file. Silberschatz, Galvin, & Gagne, Operating System Concepts Essentials, John Wiley & Sons, Inc., 2011 Files consist of a sequence of bytes representing a variety of data types. Programs determine the meaning of the data.
FILE PROPERTIES Physically, the contents of a file may be scattered across secondary memory 0 1 2 Logically, the contents of a file may be viewed as an array position pointer Each byte in a file is like one array element . . . Each byte is addressable by an offset from the beginning of the file The OS maintains a position in an open file that is updated by read or write operations n-1
ios streambuf filebuf #include <iostream> #include <fstream> ifstream istream ostream ofstream STREAM CLASSES istream cin; iostream ostream cout; fstream
USING STREAMS CONSOLE I/O FILE I/O int i; ifstream input( data1.txt ); double d; ofstream output( data2.txt ); cin >> i; input >> i; cout << d << endl; output << d << endl;