File Processing Concepts and Methods

processing files n.w
1 / 8
Embed
Share

Explore the concepts of file processing such as access control, order, size, and functions like .eof(), sequential reads, random access, and more. Learn about handling file streams and characters while ensuring correct processing.

  • File Processing
  • Data Access
  • Streams
  • EOF
  • Programming

Uploaded on | 0 Views


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


  1. PROCESSING FILES Access order and size Control: eof(), EOF, and operator bool Delroy A. Brinkerhoff

  2. FILE PROCESSING ORDER Sequential Reads or writes data from beginning to end Random / Direct Read or write data in any order Access data by address Keyed / Indexed Requires a key or index file

  3. FILE PROCESSING DATA SIZE Physical access in fixed-sized blocks Operating system hardware storage Logical access in convenient units Characters or bytes Lines Logical blocks

  4. FILE PROCESSING SUMMARY Order Sequential Random Size Character Line Block Buffer Text & Binary Text Binary (infrequently) Text & Binary Binary

  5. THE eof FUNCTION INCORRECT CORRECT ifstream file(file_name); ifstream file(file_name); while (! file.eof()) // 1 { // read file // process data } // initial file read // 1 while (! file.eof()) // 2 { // process data // read file } // 2 // 3 // 3 // 4

  6. SEQUENTIALLY READING CHARACTERS int main() { ifstream in("data.txt"); char c; istream& operator>>(int& c); istream& get(char& c); int get(); in >> c; while (!in.eof()) { cout << '|' << c << '|' << endl; in >> c; } return 0; }

  7. CHARACTER INPUT AND EOF int main() { ifstream in("data.txt"); int c; while ((c = in.get()) != EOF) cout << (char)c << endl; return 0; }

  8. operator bool operator bool int main() { ifstream in("data.txt"); char c; Overloaded casting operator Stream Boolean failbit set if an I/O operation fails while (in.get(c)) cout << '|' << c << '|' << endl; badbit set if a stream is corrupted The conversion operator returns true if either flag is set, false otherwise return 0; } Returns: !(failbit | badbit)

Related


More Related Content