29
File Input & Output Lesson xx

File Input & Output Lesson xx

  • Upload
    leiko

  • View
    50

  • Download
    0

Embed Size (px)

DESCRIPTION

File Input & Output Lesson xx. Objectives. Data Streams Numeric Output Numeric Input Multiple Numeric Output Multiple Numeric Input Character Output Character Input String Output String Input Current Position Pointer. Streams. Input and output is accomplished via streams in C++. - PowerPoint PPT Presentation

Citation preview

Slide 1

File Input & OutputLesson xx

In this module, well talk about file input and output.1ObjectivesData StreamsNumeric OutputNumeric InputMultiple Numeric OutputMultiple Numeric InputCharacter OutputCharacter InputString OutputString InputCurrent Position Pointer

Our goal is cover the following topics regarding files: Data Streams , Numeric Output, Numeric Input, Multiple Numeric Output, Multiple Numeric Input, Character Output, Character Input, String Output, String Input and the current position pointer.

2Streams Input and output is accomplished via streams in C++. A stream is a flow (movement) of data

In order to talk about file input and output, we need to talk about streams and then review console I/O. Any type of I/O is accomplished via streams in C++. You may not be aware of it, but you have already been using streams to do I/O from the keyboard and to the screen. You have been using cin and cout which are stream objects of the istream and ostream class. A stream is a flow (movement) of data. If the flow is out of your program the stream is called an output stream. If the flow is into your program, the stream is called an input stream.

3Console I/Oint a;cin >> a;

cout > a; this reads in an item of input from the keyboard. cout > a;

fout > a;

cout x; reads data from a file into x. fout.put(ch); writes the character in ch onto the file. fin.get(ch); reads in 1 character from the file. fout > a) cout a) cout a ) , the computer starts reading from where CP is pointing and stops when it encounters white space. In this case, the #10 is read into a.27Current Position Pointer (CP) ifstream fin; fin.open("junk.dat"); int a; while (fin >> a) cout