04 - File Streams - Engineering 101 More About Streams...

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

View Full Document Right Arrow Icon
1 Engineering 101 File Streams Quote of the Day - Confucius Be not ashamed of mistakes and thus make them crimes. The fstream Library s 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. s fstream adds two new types: ifstream and ofstream. s These stand for input file stream and output file stream respectively. s 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. More About Streams s There is another output stream we can access through the iostream library: cerr s cerr stands for “standard error” s cout is buffered s The output does not go directly to the screen. s cerr is not buffered s cout is tied to cin s Whenever cin is used the cout buffer is “flushed” More About Streams You (the user) The computer OS Your Executable cin cout cerr ostream cout, cerr operations << The fstream Library istream cin operations >> ifstream ofstream
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Reading From Files s 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”); s 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 2
Image of page 3
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 / 4

04 - File Streams - Engineering 101 More About Streams...

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

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