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

Info icon This 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 square6 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. square6 fstream adds two new types: ifstream and ofstream. square6 These stand for input file stream and output file stream respectively. square6 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 square6 There is another output stream we can access through the iostream library: cerr square6 cerr stands for “standard error” square6 cout is buffered square6 The output does not go directly to the screen. square6 cerr is not buffered square6 cout is tied to cin square6 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
Image of page 1

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

View Full Document Right Arrow Icon
2 Reading From Files square6 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”); square6 This line will open a file called thisfile.txt and
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern