C++ Introduction : C++ compilation Standard Input/Output: cin, cout Functions Array, Pointer class File Input/Output.

Slides:



Advertisements
Similar presentations
C++ provides the following classes to perform output and input of characters to/from files: ofstream: Stream class to write on filesofstream ifstream:
Advertisements

Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
© 2000 Scott S Albert Structured Programming 256 Chapter 7 Streams and File I/O.
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 4 Programming with Data Files.
1 11/3/08CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
計算機概論實習 Files and Streams C++ views file as sequence of bytes Ends with end-of-file marker n-1 end-of-file marker 67 This is.
1 Programming with Data Files Chapter 4 2 Standard Input Output C++ Program Keyboard input cin Output Screen cout.
CS-212 C++ I/O Dick Steflik. C++ I/O Modeled after UNIX’s concept of a “stream” –conceptionally a stream is a continuous flow of characters/bytes from.
1 Programming with Data Files Chapter 4. 2 Standard Input Output C++ Program Keyboard input cin Output Screen cout.
1 10/29/07CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
Programming with Data Files Chapter 4. Standard Input Output C++ Program Keyboard input cin Output Screen cout.
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.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
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.
CSCE 121: Introduction to Program Design and Concepts J. Michael Moore Fall 2014 Set 11: More Input and Output 1 Based on slides created by Bjarne.
Stream Handling Streams - means flow of data to and from program variables. - We declare the variables in our C++ for holding data temporarily in the memory.
Darbas su failais Arnas Terekas IT 1gr. Vilniaus universitetas Matematikos ir informatikos fakultetas.
C Basic File Input/Output Manipulation C Programming – File Outline v File handling in C - opening and closing. v Reading from and writing to files.
Copyright  Hannu Laine C++-programming Part 1 Hannu Laine.
C++ Introduction : C++ compilation. Visual Studio 2008 : Creating Command-Line Program.
File handling in C++ BCA Sem III K.I.R.A.S. Using Input/Output Files Files in C++ are interpreted as a sequence of bytes stored on some storage media.
Monday, Mar 31, 2003Kate Gregory with material from Deitel and Deitel Week 12 Labs 4 and 5 are back File IO Looking ahead to the final.
File I/O 1 ifstreams and ofstreams Sections 11.1 & 11.2.
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.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 12 Advanced File Operations.
Input/Output CSci 588: Data Structures, Algorithms and Software Design Fall 2011 All material not from online sources copyright © Travis Desell, 2011
File Handling in C++.
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.
11 Introduction to Object Oriented Programming (Continued) Cats.
Declaring fstream Objects An istream object named cin connects program and keyboard An ostream object named cout connects the program and the screen These.
Learners Support Publications Working with Files.
Lecture 14 Arguments, Classes and Files. Arguments.
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.
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.
Ms N Nashandi Dr SH Nggada 2016/01/03Ms N Nashandi and Dr SH Nggada1 Week 6 -File input and output in C++
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.
Introduction to Programming
Lecture 9 Files, Pointers
Auburn University COMP 3000 Object-Oriented Programming for Engineers and Scientists File I/O Dr. Xiao Qin Auburn University.
Basic Input and Output Operations
COMP 2710 Software Construction File I/O
Data Streams.
File I/O.
File I/O with Records Lesson xx
Interactive I/O Input from keyboard Must prompt user User friendly
Basic File I/O and Stream Objects
آشنایی با ساختارها و کار با فایلها
Today’s Lecture I/O Streams Tools for File I/O
when need to keep permanently
Text Files All the programs you've seen so far have one thing in common: Any data the program uses or calculates is lost when the program ends. In order.
Topics Input and Output Streams More Detailed Error Testing
Standard Input/Output Stream
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Introduction to C++ Programming Language
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
File I/O.
CHAPTER 4 File Processing.
Reading from and Writing to Files
Programming with Data Files
Lecture 9 Files Handling
Reading from and Writing to Files
Presentation transcript:

C++ Introduction : C++ compilation Standard Input/Output: cin, cout Functions Array, Pointer class File Input/Output

Visual Studio 2008 : Creating Command-Line Program

Visual Studio 2008 Creating Command-Line Program

C++ Introduction : C++ program structure

It is OK to use C code in C++ program

C++ Introduction : C++ Standard Input/Output

Standard Output (cout) cout : screen stream object

Standard Input (cin) cin : keyboard stream object

C++ Introduction : Functions

C++ Introduction : array/pointer/dynamic allocation Array/Pointer : almost same as C Dynamic allocation –malloc (in C)  new (in C++) –free (in C)  delete (in C++) Ex) in C int *x; x=(int*)malloc(10*sizeof(int)); … free(x); Ex) in C++ int *x; x=new int[10]; … delete[] x;

C++ Introduction : C++ class

class class : data structure type that can contain member data and member functions.

class constructor/destructor –member function that is automatically called when the object is created/deleted.

pointers to class object

C++ Introduction : Input/Output with Files

file stream class –ofstream: stream class to write on files –ifstream: stream class to read from files –fstream: stream class to read and write from/to files

File Processing File Open –Text? Or Binary? –In case of writing, append? Or truncate? –File Position (automatic? Or User-Control?) File open File Processing (Read/Write) File close

File open mode

File Open/Close Default mode Check if file open was OK Closing a file

Text File (Write)- Example

Text File (Read) - Example

Status Check

Get and Put Stream Positioning tellg()/tellp() –Returns current get/put position seekg()/seekp() –Change the location of the get/put position seekg(position); seekp(position); seekg(offset, direction); seekp(offset, direction);

File Position Example

Binary File Processing