L09_file_IO - File I/O input from files opening files...

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

View Full Document Right Arrow Icon
EECS 183 University of Michigan File I/O Mary Lou Dorf File I/O File I/O input from files opening files connecting to input stream fstream eof marker stream states
Background image of page 1

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

View Full DocumentRight Arrow Icon
EECS 183 University of Michigan File I/O Mary Lou Dorf Two main types of files: text and binary Text file: comprised of ASCII characters examples ? Binary file: structure/contents determined by program which wrote it examples ? files you type with MS Visual; files you type with pico, simpletext, notepad, wordpad MSWord files, jpg, mp3 Reading Input From Files & Other Input Reading Input From Files & Other Input Options Options
Background image of page 2
EECS 183 University of Michigan File I/O Mary Lou Dorf int main ( ) { char ch; ch = 'X’; cout << ch; return (0); } Example Text File Example Text File end of line marker end of file marker <\n> <\n> <\n> <\n> <\n> <\n> <\n> <eof> <tab> <tab> <tab> <tab>
Background image of page 3

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

View Full DocumentRight Arrow Icon
EECS 183 University of Michigan File I/O Mary Lou Dorf Sample “rtf” – same code Sample “rtf” – same code {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswi ss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\f0\fs20 int main()\par \{\par \tab char ch;\par \tab ch = 'X';\par \tab cout << ch;\par \tab return (0);\par \}\par \par }
Background image of page 4
EECS 183 University of Michigan File I/O Mary Lou Dorf cin ( type istream ) cout ( type ostream ) keyboard screen executing program input data output data Input: keyboard Input: keyboard Output: Monitor Output: Monitor
Background image of page 5

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

View Full DocumentRight Arrow Icon
EECS 183 University of Michigan File I/O Mary Lou Dorf #include <fstream> your file variable ( type ifstream ) cout ( type ostream ) disk file “myInFile.dat” screen executing program input data output data Input: File Input: File Output: Monitor Output: Monitor
Background image of page 6
EECS 183 University of Michigan File I/O Mary Lou Dorf #include <fstream> your file variable ( type ifstream ) your file variable ( type ofstream ) disk file “myInFile” disk file “myOutFile” executing program input data output data Input: File Input: File Output: File Output: File
Background image of page 7

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

View Full DocumentRight Arrow Icon
EECS 183 University of Michigan File I/O Mary Lou Dorf 1) #include <fstream> contains data types ifstream , ofstream , and functions open and close 2) Declare a file stream variable to represent the file you intend to use ifstream ins; ofstream outFile; 3) Open the file ins.open(“data.txt”); outFile.open(“output.txt”); 4) Use this variable (file stream) to read or write ins >> num; outFile << num; 5) Close the file when done with it ins.close(); Performing Basic Text file I/O Performing Basic Text file I/O
Background image of page 8
EECS 183 University of Michigan File I/O Mary Lou Dorf 15 5 Q<\n> <eof> assume that the file is named data.txt assume that the file is stored in the same folder as your MS Visual project file read pointer (read marker) points at next char to be read Example: read from disk file Example: read from disk file
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/12/2010 for the course EECS 183 taught by Professor Dorf during the Fall '08 term at University of Michigan.

Page1 / 32

L09_file_IO - File I/O input from files opening files...

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

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