Start. File Streams 03/04/11 Stream as Connection to I/O.

Slides:



Advertisements
Similar presentations
CMSC 2021 C++ I/O and Other Topics. CMSC 2022 Using C++ Stream I/O Default input stream is called cin Default output stream is called cout Use the extraction.
Advertisements

File I/O in C++. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk);is stored on a secondary storage device.
Programming File I/O. COMP102 Prog. Fundamentals File I/O / Slide 2 Copyright © 2000 by Brooks/Cole Publishing Company A division of International Thomson.
1 Lecture 19 Chapter 4 Program Input and the Software Design Process Dale/Weems/Headington.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
C++ plus. 2 Goals Some general C++ tips 3 C++ Tips is header file for a library that defines three stream objects Keyboard an istream object named cin.
 Wednesday, 10/16/02, Slide #1 CS106 Introduction to CS1 Wednesday, 10/16/02  QUESTIONS??  Today:  Return and discuss Test #1  Input from and output.
1 File I/O In C++, I/O occurs in streams. A stream is a sequence of bytes Each I/O device (e.g. keyboard, mouse, monitor, hard disk, printer, etc.) receives.
Programming File I/O. COMP102 Prog. Fundamentals File I/O / Slide 2 Copyright © 2000 by Brooks/Cole Publishing Company A division of International Thomson.
Streams, Files. 2 Stream Stream is a sequence of bytes Input stream In input operations, the bytes are transferred from a device to the main memory Output.
Functions.
CSC 107 – Programming For Science. Today’s Goal ALL  Understand why ALL I/O is file I/O  Common bugs to avoid when coding with files in C++  Get a.
Chapter 8 Streams and Files Lecture Notes Prepared By: Blaise W. Liffick, PhD Department of Computer Science Millersville University Millersville, PA
In Addition... To the string class from the standard library accessed by #include C++ also has another library of string functions for C strings that can.
STREAMS AND FILES OVERVIEW.  Many programs are "data processing" applications  Read the input data  Perform sequence of operations on this data  Write.
Chapter 8 Data File Basics.
1 CS 101 Lecture 2. 2 Input from the Keyboard Here is a program to accept input from the keyboard and put into into two variables. #include main(){ cout.
C++ Lecture 8 Monday, 25 August I/O, File, and Preprocessing l An in-depth review of stream input/output l File handling in C++ l C++ preprocessing.
C++ Introduction : C++ compilation. Visual Studio 2008 : Creating Command-Line Program.
C++ Coding and Compiling. Why QT/C++ Over Java?  Java is easier than C++  Java has built in GUIs  Java is multi-platform  C/C++ is more used in industry.
Data Types & I/O Streams Objectives Data Types Understand that integers form the underlying foundation for many data types. Introduce a few frequently.
1 firstlastnextprevioushome richard jones COMP103A Introduction to Computer Science 1 Richard Jones G2.04
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
TEXT FILES. CIN / COUT REVIEW  We are able to read data from the same line or multiple lines during successive calls.  Remember that the extraction.
I/O in C++ October 7, Junaed Sattar. Stream I/O a stream is a flow of bytes/characters/ints or any type of data input streams: to the program output.
FILE I/O IN C++. Using Input/Output Files A computer file  is stored on a secondary storage device (e.g., disk);  is permanent;  can be used to provide.
Basics of Most C++ Programs // Programmer: Clayton Price date: 9/4/ // File: fahr2celc.cpp 03. // Purpose:
Disk Files for I/O your variable (of type ifstream) your variable (of type ofstream) disk file “myInfile.dat” disk file “myOut.dat” executing program input.
Objective: Students will be able to: Declare and use variables Input integers.
1 Character Strings (Cstrings) Reference: CS215 textbook pages
Quiz // // The function exchanges the two parameters. // Param: ( ) // Param:
Fahrenheit and Celsius
1 CSC 221: Introduction to Programming Fall 2011 Input & file processing  input vs. raw_input  files: input, output  opening & closing files  read(),
C++ REVIEW INPUT/OUTPUT (I/O). BRIEF NOTE “CLASSES” AND “STRUCTS” AND “TYPES” They are ADTs… They define data and operations on that data The ADTs in.
Input/Output CSci 588: Data Structures, Algorithms and Software Design Fall 2011 All material not from online sources copyright © Travis Desell, 2011
1 CS 1430: Programming in C++. 2 Input: Input ends with -1 Sentinel-Controlled Loop Input: Input begins with.
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
Streams One of the themes of this course is that everything can be reduced to simple (and similiar) concepts. Streams are one example. Keyboard and Screen.
Homework 1 (due:April 8th) Deadline : April 8th 11:59pm Where to submit? eClass “ 과제방 ” ( How to submit? Create a folder. The name.
Declaring fstream Objects An istream object named cin connects program and keyboard An ostream object named cout connects the program and the screen These.
Lecture 14 Arguments, Classes and Files. Arguments.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 8: Streams and Files Problem Solving, Abstraction, and Design using.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Today’s Lecture  I/O Streams  Console I/O  File I/O  Tools for File I/O  Sequential.
File I/O in C++. Using Input/Output Files A computer file  is stored on a secondary storage device (e.g., disk);  is permanent;  can be used to provide.
Introduction to Cryptography Lecture 4. Caesar Cipher Gaius Julius Caesar (100 B.C.- 44 B.C.) General Politician Dictator of Rome Creator of Caesar Cipher.
CS 1430: Programming in C++ 1. File Input in VS Project Properties Debugging Command Arguments quiz8-1.out We want to know how to do it ourselves, right?
Module 5: I/O and Strings #1 2000/01Scientific Computing in OOCourse code 3C59 Module 5: I/O and STRINGS In this module we will cover The C++ input and.
Computer Programming II Lecture 9. Files Processing - We have been using the iostream standard library, which provides cin and cout methods for reading.
Programming II I/O Streams and Data Files 1(c) Asma AlOsaimi.
CS212: Object Oriented Analysis and Design
Chapter 14: Sequential Access Files
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
What Actions Do We Have Part 1
Chapter 8 (Part 3) Library Classes for Strings (P.405)
TEMPERATURE CONVERSION
Standard Input/Output Streams
Standard Input/Output Streams
File I/O.
Programming with Data Files
Today’s Lecture I/O Streams Tools for File I/O
Standard Input/Output Stream
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Chapter 3 Input output.
File I/O.
Programming File I/O.
Lecture 2 Fall 2011 September 13-15, 2011 Ghufran Ahmed
CPS120: Introduction to Computer Science
File Streams 12/09/13.
Chapter 8 (Part 3) Library Classes for Strings (P.405)
Presentation transcript:

Start

File Streams 03/04/11

Stream as Connection to I/O

Example of Creating a Stream  Program that outputs a quote to a file  writefile.cpp

To Connect Stream to File Header File #include Declare stream & open file ifstream fs_in(“mydata”, ios::in); ofstream fs_out(“myout”, ios::out);

To Connect Stream to File 3. Input/Output fs_in >> x; fs_out \n”; 4. Close fs_in.close( ); fs_out.close( );

Example of Input  Write a program to input a list of positive numbers from a file, then output the sum. –Create stream and connect to file. –Input number from input stream –While number not negative – Add number to sum – Input number from input stream –Output sum –Close stream streams4.2/sum.cpp

Another Problem Start Here  Write a program to input a file of five temperatures in degrees Celsius. Convert the temperatures to Fahrenheit and output them to another file. Use a function to do the conversion. What would the algorithm be? Let's write the program.(f = 9/5c + 32) celsius.txt

Sentinel Data in a File  Value that is not part of the data marks the end of a list.  I am going to use '*' as a sentinal to mark the end of data in some character input in the next example.

Caesar Cipher  Using the Caesar Shift (2 to the right), the message.  "RETURN TO ROME" would be encrypted as, "TGVWTP VQ TQOG"  Essentially, add +2 to the ascii value of a character.  To decode shift it back by -2

Caesar Cipher  When using cin with characters, spaces are skipped.  cin.get() inputs the spaces, too.

Caesar Cipher  Write a program that inputs a message from the keyboard and saves the coded version in a file called code.txt  Stop input when the sentinel, '*', is found.  cipher2.cpp uses a cin.get() so that spaces won't be skipped.

Exercise  p. 122, #2  Read sec. 7.3 for Friday.