04 - File Streams - Engineering 101 File Streams Quote of...

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

View Full Document Right Arrow Icon
Engineering 101 File Streams
Background image of page 1

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

View Full DocumentRight Arrow Icon
Quote of the Day - Confucius Be not ashamed of mistakes and thus make them crimes.  
Background image of page 2
The fstream Library n If we include the fstream library by typing #include <fstream> then we can define new streams that can get input  from, and direct output to, files. n fstream  adds two new types:  ifstream  and  ofstream . n These stand for input file stream and output file  stream respectively. n An  ifstream  is a sub-type of  istream  and  ofstream  is a  sub-type of  ostream  so they can be used just like  cin   and  cout .
Background image of page 3

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

View Full DocumentRight Arrow Icon
More About Streams n There is another output stream we can access  through the  iostream  library:   cerr n cerr  stands for “standard error” n cout   is  buffered n The output does not go directly to the screen. n cerr   is not  buffered n cout  is tied to  cin n Whenever  cin  is used the  cout  buffer is “flushed”
Background image of page 4
More About Streams You (the user) The computer OS Your Executable cin cout cerr
Background image of page 5

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

View Full DocumentRight Arrow Icon
ostream cout, cerr operations << The fstream Library istream cin operations >> ifstream ofstream
Background image of page 6
n To read from a file you first must declare a  new ifstream and open it.  This is done with a  line of the form: ifstream infile(“thisfile.txt”); n This line will open a file called thisfile.txt and  create a new ifstream called infile to extract  input from the file by lines like: infile >> x >> y;
Background image of page 7

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

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

This note was uploaded on 01/30/2012 for the course ENGR 101 taught by Professor Ringenberg during the Winter '07 term at University of Michigan.

Page1 / 21

04 - File Streams - Engineering 101 File Streams Quote of...

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

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