 Data Streams  Numeric Output  Numeric Input  Multiple Numeric Output  Multiple Numeric Input  Character Output  Character Input  String Output.

Slides:



Advertisements
Similar presentations
 2003 Prentice Hall, Inc. All rights reserved. 1 Recursion Recursive functions –Functions that call themselves –Can only solve a base case If not base.
Advertisements

File I/O. COMP104 Lecture 20 / Slide 2 Using Input/Output Files * A computer file n is stored on a secondary storage device (e.g., disk) n is permanent.
File I/O. COMP104 Lecture 20 / Slide 2 Using Input/Output Files (Review) * A computer file n is stored secondary storage devices (hard drive, CD) n can.
1 11/3/08CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
File I/O. COMP104 File I/O / Slide 2 Using Input/Output Files * A computer file n is stored on a secondary storage device (e.g., disk) n is permanent.
1 Programming with Data Files Chapter 4 2 Standard Input Output C++ Program Keyboard input cin Output Screen cout.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
1 Programming with Data Files Chapter 4. 2 Standard Input Output C++ Program Keyboard input cin Output Screen cout.
CS 1400 Pick ups from chapters 2 and 3. #include directive This pre-processing directive causes the textual contents of a named file to be inserted into.
CS 1400 Feb 2007 Pick ups from chapters 2 and 3. Example; A person 15 years of age may acquire a driver’s lic. with permission from parents. A person.
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.
This set of notes is adapted from that provided by “Computer Science – A Structured Programming Approach Using C++”, B.A. Forouzan & R.F. Gilberg, Thomson.
DATA FILE HANDLING. Contents to be covered in class  Concept of files & streams  Stream class hierarchy  File handling functions  Text V/S Binary.
Arithmetic Operators Operation Operator Example Addition = 9 Subtraction = 1 and = -1 Multiplication * 5 * 4 = 9 Division (integer)
 Write a program that uses a one dimension to do a table look-up  Learn about parallel arrays.
 Review structures  Program to demonstrate a structure containing a pointer.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
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.
File I/O ifstreams and ofstreams Sections 11.1 &
File I/O ifstreams and ofstreams. Some istream Operations istream function Description cin >> ch; Extract next non-whitespace character from cin and store.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Fall 2012 Lecture 8: File I/O; Introduction to classes.
File I/O 1 ifstreams and ofstreams Sections 11.1 & 11.2.
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.
Computer Programming TCP1224 Chapter 13 Sequential File Access.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
C++ Streams © Bruce M. Reynolds & Cliff Green, C++ Programming Certificate University of Washington Cliff Green.
C++ FILE I/O.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT11: File I/O CS2311 Computer Programming.
COMP102 Lab 071 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
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.
Practice Building Classes Modeling Objects. Problem Write a program that computes the Dean’s List (full-time students whose GPA 3.0), using a student.
Module 4: I/O and Strings #1 2000/01Scientific Computing in OOCourse code 3C59 Module 4: I/O In this module we will cover Keyboard/screen input and output.
 for loop  while loop  do-while loop for (begin point; end point ; incrementation ) { //statements to be repeated }
Vectors One-Dimensional Containers. Problem A file contains a sequence of names and scores: Ann92 Bob84 Chris89... Using OCD, design and implement a program.
Quiz 2 Results. What Is Wrong? #include using namespace std int Main() { // Say Hello 4 times for(i == 0; i < 3; i++) { cout >> "Hello World!"
Chapter 11 Standard C++ Strings and File I/O Dept of Computer Engineering Khon Kaen University.
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.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 9. Streams & Files.
Program Input and the Software Design Process ROBERT REAVES.
 Random access vs. sequential access  Current position pointer (CP)  Record numbers  seekg command  tellg command  Program using random access.
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
FILE HANDLING(WORKING WITH FILES) FILE- A file is a collection of related data stored in a particular area on the disk. STREAMS- interface between the.
24 4/11/98 CSE 143 Stream I/O [Appendix C]. 25 4/11/98 Input/Output Concepts  Concepts should be review!  New syntax, but same fundamental concepts.
File I/O in C++ I. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk); is permanent; can be used to provide.
C++ CSCE 343.
ifstreams and ofstreams
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
CS Computer Science IA: Procedural Programming
Parallel Arrays Parallel array =>Two or more arrays with the same number of elements used for storing related information about a collection of data. Example:
Review of Strings which include file needs to be used for string manipulation? what using statement needs to be included fro string manipulation? how is.
Data Streams.
File I/O with Records Lesson xx
Basic File I/O and Stream Objects
File Streams and File I/O
Programming with Data Files
Today’s Lecture I/O Streams Tools for File I/O
Sequential input and output Operations in file
when need to keep permanently
Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Standard Input/Output Stream
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Sindhu S PGT Comp.Sc. K V Kollam
File I/O.
CS150 Introduction to Computer Science 1
File I/O.
Programming with Data Files
ifstreams and ofstreams
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Presentation transcript:

 Data Streams  Numeric Output  Numeric Input  Multiple Numeric Output  Multiple Numeric Input  Character Output  Character Input  String Output  String Input  Current Position Pointer

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

int a; cin >> a; cout << a;

//file I/O int a; fin >> a; fout << a; //console I/O int a; cin >> a; cout << a;

#include using std::ofstream; int main() { ofstream fout; fout.open("junk.dat"); int a = 17; fout << a; fout.close(); return 0; }

#include using std::ofstream; int main() { ofstream fout; fout.open("junk.dat"); int a = 17; fout << a; fout.close(); return 0; }

#include using std::ofstream; int main() { ofstream fout; fout.open("junk.dat"); int a = 17; fout << a; fout.close(); return 0; }

1. Include the correct header files 2. Set up a stream object 3. Attach a file to the stream object 4. Write to file using the stream object 5. Close file

# include using std::ifstream; int main() { ifstream fin; fin.open("junk.dat"); int a; fin >> a; fin.close(); return 0; }

#include using std::ifstream; int main() { ifstream fin; fin.open("junk.dat"); int a; fin >> a; fin.close(); return 0; }

#include using std::ifstream; int main() { ifstream fin; fin.open("junk.dat"); int a; fin >> a; fin.close(); return 0; }

#include using std::ofstream; using std::endl; int main() { ofstream fout; fout.open("junk.dat"); int i; for (i = 10; i < 110; i += 10) fout << i << endl; fout.close(); return 0; }

fout << i << endl ; fout << i ;

#include using std::ifstream; #include using std::cout; int main() { ifstream fin; fin.open("junk.dat"); int a; while (fin >> a) cout << a << endl ; fin.close(); return 0; } junk.dat

#include using std::ifstream; #include using std::cout; int main() { ifstream fin; fin.open("junk.dat"); int a; while (fin >> a) cout << a << endl ; fin.close(); return 0; } junk.dat

#include #include using std::ofstream; #include using std::cin; int main() { char ch; ofstream fout; fout.open("test.dat"); while ( cin.get(ch) && (ch != '\n') ) fout.put(ch);

char buf[] = "Feed a child fish & he eats for one day. Teach him to fish and he eats forever."; int i; for (i = 0; i < (int)strlen(buf); ++i) fout.put(buf[i]); fout.close(); return 0; }

#include using std::ifstream; #include using std::cout; int main() { char ch; ifstream fin; fin.open("test.dat"); while(fin.get(ch)) cout << ch; fin.close(); return 0; }

#include using std::ofstream; using std::ios; #include using std::cin; using std::endl; #include

int main() { char buf[80]; ofstream fout; fout.open("test.dat"); while(cin.getline(buf, 80) &&(strlen(buf) > 0)) fout << buf << endl;

fout << "Better to remain quiet\n"; fout << "and be thought a fool\n"; fout << "that to open one's mouth\n"; fout << "and erase all doubts.\n"; fout.close(); return 0; }

#include using std::ifstream; #include using std::cout; using std::endl; int main() { char buf[80]; ifstream fin; fin.open("test.dat"); while(fin.getline(buf, 80)) cout << buf << endl; fin.close(); return 0; }

#include using std::ifstream; #include using std::cout; using std::endl; int main() { char buf[80]; ifstream fin; fin.open("test.dat"); while(fin.getline(buf, 80)) cout << buf << endl; fin.close(); return 0; }

fout << x; //write x to file fin >> x; //read data from file into x fout.put(ch); //write character in ch onto file fin.get (ch); //read 1 character from file into ch fout << “Kow\n"; //write a string onto file fin.getline(b, 80); //read a string into array b

ifstream fin; fin.open("junk.dat"); int a; while (fin >> a) cout << a << endl ; junk.dat CP

ifstream fin; fin.open("junk.dat"); int a; while (fin >> a) cout << a << endl ; junk.dat CP

ifstream fin; fin.open("junk.dat"); int a; while (fin >> a) cout << a << endl ; junk.dat CP

Data Stream Numeric Output Numeric Input Multiple Numeric Output Multiple Numeric Input Character Output Character Input String Output String Input Current Position Poi nter