Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Ch - 7. Data File Handling

Size: px
Start display at page:

Download "Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Ch - 7. Data File Handling"

Transcription

1 Introduction Data File Handling The fstream.h Header file Data Files Opening and Closing File Steps to process a File in your Program Changing the behavior of Stream Sequential I/O With Files Detecting EOF File Pointers and Random Access Basic Operation on Files Error Handling During I/O

2 Introduction of File Most Computer Programs work with files. Word Processor creates documents file, Database creates files of Information, Compilers read source file and generates executable files. So, File itself is a bunch of bytes stored on some storage device like tape, or Magnetic disk etc. In C++, File Input/Output facility are implemented through a component header file of C++ standard library. This header file is fstream.h

3 fstream.h Header File The C++ input/output operation are very much similar to the console input and output operation. The file operations also make use of streams as an interface between the programs and the files. What is stream? A stream is a sequence of Bytes. A stream is a general name given to a flow of data. Different streams are used to represent different kind of data flow. Each streams is associated with a particular class.

4 Continue Each stream is associated with particular class, which contains member function and definitions for dealing with that particular kind of data flow. The istream class represent input disk file. The streams that supplies data to the program is known as input stream. It read the data from the file and hands it over to the program. The streams that received data from program is known as output stream. It writes the received data to the file.

5 Text File A text file stores information in ASCII characters. In text files, each line of text is terminated, with special characters known as EOL (End of Line) characters. In text files some internal translations take place when this EOL characters is read or written.

6 Binary Files A Binary file just a file that contains information in the same way as it store in memory. In binary file, there is no delimiters for a line. In binary file, no translation occurs. Binary files are faster and easier for a program to read and write than a text file. Binary files are best way to store information In C++, the default file system is Text file.

7 Opening the Files In C++, for open a file, you must first obtains a stream. There are three types of Stream; Input, Output and Input- Output. To create an Input stream, declare the stream to be of class istream. To create an Output stream, declare the stream to be of class ostream. Stream that will perform both input and output operation must be declared as fstream. Opening a file can be achieved in two ways. (1) Using the constructor function of the stream class. (2) Using the function open()

8 When we open a file with Constructor This method is preferred, when a single file is used with a stream. When we open a file by open() method This method is preferred, when we want to manage multiple files with same stream.

9 Opening file using Constructor To open a file, Data file as an input file ( it means we will read from it, but can not modifying it. And no other operation like writing and modifying is possible). We shall create a file stream object of input type. ifstream type. Syntax : ifstream inputfile( Datafile ); Here inputfile is the object of ifstream class and Datafile is the file name to open in input mode. After creating the object, datafile is open and attach with object inputfile.

10 How to read data from file To read the data from this file, object of inputfile is used and by using getfrom operator >> Syntax char ch; inputfile >>ch; float amt; inputfile >>amt;

11 How to write into the file Similarly, when we want to write onto the file, we must open the file in output mode. This is accomplished by. Creating ofstream object to manage the output stream. Associating tat object with a particular file Syntax.. ofstream outputfile( datafile ); Here outputfile is the object and datafile is file.

12 Extra Notation about file object The connection with a file are closed automatically, when the input and output stream object expire. Also you can close connection with a file explicitly by using close() method. inputfile.close(); outputfile.close(); Closing such connection does not eliminate the stream. It just disconnect it from file.

13 Opening a file using open() function The are many situations requiring a program to open more than one file. So we need create a separate stream for each of the file. First of all, declares the stream object without initializing it, then use the second statement and associated a file name. Syntax.. ifstream infileobject; Infileobject.open( filename.dat ); To close a file. We can use infileobject.close();

14 Concept of file mode The filemode describe how a file is to be used. To read from it, to write to it, to append it and so on. When you associate a stream with file, either by constructor or by the open() function, the second argument is the mode of the file, in which it open. Syntax.. Stream_object.open ( FileName,Filemode); The second argument of open method is of int type and you can choose one of the mode of file.

15 S. No Constant Meaning Stream Type 1 ios::in It opens file for reading, in input mode ifstream 2 ios::out It opens file for writing, in output mode. This also opens the file in ios::trunk mode by default. This means an existing file is truncated when opened. It means the previous contents are discarded. 3 ios::ate This seeks to end-of-file upon opening the file, I/O operation can still occur anywhere within the file. 4 ios::app This causes all output to that file to be appended to the end. This value can be used only with files capable of output 5 ios::trunk This value causes the contents of a pre-existing file by the same name to be destroyed and truncated the file to zero length. 6 ios::noncr eate 7 ios::norepl ace This cause the open() function to fail if the file does not already exist. It will not create a new file with that name. This causes open() function to fail if the file already exist. This is used when you want to create a new file and at the same time. 8 ios::binary This causes a file to be opened in binary mode. By default, files are opened in text mode. When a file opened in text mode, various characters translations take place. Such as carriage return to new line. However no such character translation occurs in files opened in binary mode. ofstream Ifstream Ofstrea m ofstream ofstream ofstream ofstream ofstream ifstream

16 Extra Notations about file mode The ifstream and ofstream provide default mode of the file is ios::in(input mode) The fstream class does not provide the default mode. It specify explicitly. You can combine more than one file mode using bitwise (OR) operator. Ex ofstream fout; fout.open ( Master,ios::app ios::nocreate); To open a binary file add ios::binary with file mode. fout.open ( Master, ios::nocreate ios::binary);

17 Steps to process a file in your Program Determine the type of link required. Declare a stream for the desired type of link. Attach the desired file to the stream. Now process as required. Close the file-link with stream.

18 Determine the type of link required. This step is required the type of link, if the data is to be brought in from a file to memory, then the link can be said to be File-to-Memory. Similarly fif the data is sent from memory to file then the link can be said as Memory-to-file. If both side need data transfer then two-way link is created. File-to-Memory Input type Memory-to-file Output type File-to-Memory & Memory-to-file // I/O type

19 Declaring the stream for type of link After determining the type of the link, next step is create a stream for it. In order to create the file stream, the header file <fstream.h> is included in the program, and if you have <fstream.h> then no need to include <iostream.h.> as cin, cout. These are also available in <fstream.h>. istream fi; // here stream name is fi; ofstream fo; // here stream name is fo;

20 Attach desired file to declare stream In this step we want to attach a file with the created stream in second step. This can be done in two ways Using Constructor. Using open() method ifstream fin( sample.dat ); // sample.dat is a file. fin.open( sample.dat,ios::in) // ios::in file mode

21 Process as required. Under this step, whatever process is required for the given problem, is performed for instance. Close the file link with stream This is the final step where we de-link the file with stream. This is performed through close () function ifstream fin; fin.close();

22 EX #include<fstream.h> void main() ofstream filout; filout.open("marks.dat",i os::out); char ans='y'; int follno; float marks; while(ans=='y' ans=='y') cout<<endl<<"enter rollno "; cin>>rollno; cout<<endl<<"etner Marks "; cin>>marks; filout<<rollno<<"\n"<<marks<<"\n"; cout<<'\n Do you want to add more record "; cin>>ans; filout.close(); After the Executing the program, we can open the file marks.dat in notepad and see the data is reached in the file or not

23 Q. Write a C++ program to wite 5 students name in student file and again read it from file #include<fstream.h> #include<conio.h> void main() int i; ofstream fout("student"); char name[25],ch; float marks=0.0; clrscr(); for(i=0;i<5;i++) cout<<"student "<<i+1 <<":\t Name "; cin.get(name,25); cout<<"\t Marks "; cin>>marks; cin.get(ch); fout<<name<<"\n"<<marks<<"\n";

24 fout.close(); ifstream fin("student"); fin.seekg(0); cout<<"\n"; for(i=0;i<5;i++) fin.get(name,25); fin.get(ch); fin>>marks; fin.get(ch); cout<<"student Name "<<name; cout<<"\t Marks : "<<marks<< "\n "; fin.close(); getch();

25 Changing the behavior of Stream When you open a file, it means when you link a file with stream using constructor, the stream is activated in its default mode. The default mode in input type stream is ios::in and for output type stream is ios::out. The default behavior of ifstream type stream allow user to read content from the file. If the file mode is ios::in only (fin.open( abc.dat,ios::in)) then reading is performed in text file only. If the file mode is ios::in ios::binary then reading is performed on binary file.

26 Write a C++ program to append data in already stored file marks.dat #include<fstream.h> void main() ofstream fout; fout.open("marks.dat",ios::app); char ans='y'; int rollno; float marks; while(ans=='y' ans=='y') cout<<endl<<"enter Rollno "; cin>>rollno; cout<<endl<<"etner Marks "; cin>>marks; fout<<rollno<<"\n"<<marks<<"\n"; cout<<'\n Do you want to add more record "; cin>>ans; fout.close();

27 get(), getline() and put() function The function get() and put() are byte oriented. get() will read byte of data and put() will write byte of data. The get() have many forms and used as.. istream & get(char & ch); ostream & put(char ch); The get() function reads a single characters from the associated stream and put the value in ch. It returns the reference to the stream. The put write the value of ch to the stream and returns the reference to the stream.

28 Write a program to display the content of file #include<fstream.h> #include<conio.h> int main() clrscr(); char ch; ifstream fin; fin.open("c:\\ab.txt",ios::in); if(!fin) cout<<"\n Cannot open the file "; return(0); while(fin) fin.get(ch); cout<<ch; fin.close(); getch(); return 0;

29 Write a program to create a file using put() #include<fstream.h> #include<conio.h> int main() clrscr(); ofstream fout; fout.open("c:\\abc.txt",ios::out); if(!fout) cout<<"\n Cannot open the file "; return(0); for(int i=65;i<=90;i++) fout.put((char)i); fout.close(); getch(); return 0;

30 Another forms of get() Other forms of get() as follows istream & get(char *buf, int num, char delt) int get(); The first form read the characters into a character array pointed to by buf until either num character have been read or the character specified by delt has been occur. For Example char line[40]; cin.get(line,40, $ ); This will read characters into line either 40 characters or $ is encountered which ever is occur first. The second form of get() returns the next character from stream, it returns EOF if end of file encountered. Ex.. int i; char ch; ch = i = fin.get(); If A is read then value of i will 65 and ch will A

31 getline() function. This function read a line into the characters array. istream & getline(char *buf, int num, char delm) This function virtually identical with get() function This function also reads the characters from input stream and placed it onto the characters array, either number of characters specified or the delimiter character is encountered. cin.getline(a,40, $ );

32 Difference between getline() & get() The difference between get(buf,num,delt) and getline() is that getline() read and remove the delimeter new-line character from the input stream if it is encountered which is not done in get(). EX void main() char nm[40],n[40]; int i; clrscr(); cout<<"enter First String "; cin.getline(nm,40,'$'); cout<<"enter Second String "; cin.get(n,40,'%'); cout<<endl<<nm<<strlen(nm ); cout<<endl<<n<<strlen(n); getch();

33 Difference between getline() & get()

34 Programming diff. b/n get and getline #include<fstream.h> #include<conio.h> #include<string.h> void main() char nm[40],n[40],ch; int i; clrscr(); cout<<"enter First String "; cin.get(nm,40); //cin.get(ch); cout<<"enter Second String "; cin.getline(n,40); cout<<endl<<nm<<strlen(nm); cout<<endl<<n<<strlen(n); getch(); Without cin.get(ch) output is With cin.get(ch) output is

35 Read a text file and create a file that stores the text line by line along with line nos. #include<fstream.h> #include<conio.h> int main() char line[75]; int lc=0; ofstream outfile("f11.cpp",ios::app); ifstream infile("f1.cpp",ios::in); clrscr(); if (!infile) cout<<"failed to open input file "; return 0; while(!infile.eof()) // while(1) infile.getline(line,75); //if (infile.eof()) break; lc++; outfile<<lc<<":"<<line<<"\n"; infile.close(); outfile.close(); cout<<"output "<<lc<<" Records"<<endl; getch(); return 0;

36 The read() and write() function To manipulate binary data into the file we use two another function read() and write() as follow istream & read( (char *) & buf, int sizeof(buf)); ostream & write((char *) & buf,int sizeof(buf)); The data written to a file using write can only be read accurately using read().

37 Read and write a binary file using struct #include<fstream.h> #include<conio.h> #include<string.h> struct customer char name[25]; float bal;; int main() customer savec; clrscr(); strcpy(savec.name,"123546"); savec.bal= ; ofstream fout("saving",ios::out ios::binary); if (!fout) cout<<"file can't be open "; return 0; fout.write((char *) & savec, sizeof(customer)); fout.close(); ifstream fin("saving",ios::in ios::binary); fin.read((char *) & savec, sizeof(customer)); cout<<savec.name; cout<<savec.bal; getch(); return 0;

38 Read and write a binary file using class #include<fstream.h> #include<conio.h> class student char name[25]; int rollno; public: void readdata(); void printdata(); ; void student :: readdata() cout<<endl<<"enter Name "; cin>>name; cout<<endl<<"enter Rollno "; cin>>rollno; void student :: printdata() cout<<endl<<"name = "<<name; cout<<endl<<"rollno = "<<rollno; void main() fstream file; student s,t ; file.open("file.txt",ios::out ios::in ios::binary); clrscr(); s.readdata(); file.write((char *) &s, sizeof(s)); s.readdata(); file.write((char *) &s, sizeof(s)); file.seekg(0); file.read((char *) &t, sizeof(t)); t.printdata(); file.read((char *) &t, sizeof(t)); t.printdata(); getch();

39 Detecting EOF We can detect, when the end of file is reached by using the member function eof(); Syntax int eof(); ifstream fin; fin.open("master",ios::in); while(!fin.eof()) if (fin.eof()) cout<<"end of file is reached ";

40 File pointers and Random Access Every file maintain two pointers called get_pointer (in input mode file) and put_pointer (in output mode file) which is tell the current position in the file where writing and reading take place. File pointer not a pointer in c++, but it is like a book mark for the file. By these pointers we can maintain a file in random access way. This means we can read from any where and write onto any where in the file.

41 seekg(), seekp() & tellg(), tellp(). In C++ random accessing is achieved by four function called seekg(), seekp() and tellg(), tellp(). seekg() and tellg() functions are used to set the get pointers. Similarly seekp() and tellp() are used to set the put_pointers. The seekg() and tellg() functions are used in ifstream and seekp() and tellp() functions are used in ofstream If we use these function with fstream object then the tellg and tellp returns the same value and seekg and seekp works in the same way.

42 SYNTAX Ex seekg() : istream & seekg(long); // form 1; istream & seekg(long,seek_dir); // form 2; seekp() : ostream & seekp(long); // form 1; ostream & seekp(long,seek_dir); // form 2; tellg() - returns long get_pointers; tellp() - returns long put_pointers; Seek_dir fin.seekg(30); will move the get_pointer to byte no 30; fin.seekp(30); will move the put_pointer to byte no 30; ios::beg // refers to beginning of the file. ios::cur // refers to current of the file. ios::end // refers to end of file.

43 EXAMPLES fin.seekg(30,ios::beg); // goto byte no 30 from the beginning of the file; fin.seekg(-5,ios::cur); // goto back 5 bytes from the current position; fin.seekg(0,ios::end);; // goto the end of the file; fin.seekg(-5,ios::end); // goto 5 byte back from end of file

44 Basic operations on Binary Files There are some operations performs on binary files like.. Searching Appending Data Inserting Data on Sorted File Deleting a Record Modifying Data

45 Search Data from File using class #include<fstream.h> #include<conio.h> class student char name[25]; int rollno; public: void readdata(); void printdata(); int getrollno() return(rollno); ; void student :: readdata() cout<<endl<<"enter Name "; cin>>name; cout<<endl<<"enter Rollno "; cin>>rollno; void student :: printdata() cout<<endl<<"name = "<<name; cout<<endl<<"rollno = "<<rollno; void main() char ch; int rno; fstream file; student s,t ; file.open("file.txt",ios::out ios::in ios::binary); clrscr(); while(1) s.readdata(); file.write((char *) &s, sizeof(s)); cout<<"do you Continue (Yes for Y or y) ";

46 CONTINUE cin>>ch; if (ch!='y' && ch!='y') break; cout<<endl<<"enter Rollno to be search : "; cin>>rno; ch='n'; file.seekg(0); while(!file.eof()) file.read((char *) &t, sizeof(t)); if (t.getrollno()==rno) cout<<endl<<"data Found "<<endl; t.printdata(); ch='y'; if (ch=='n') cout<<endl<<"data Not Found "; getch();

47 Appending Data to the File. To append data in the file, the opened file in two mode. File is opened in output mode ios::out File is opened in append mode ios::app Once the file get opened in app mode, the old data will retained and new data get appended to the file

48 Append Data in the File using class #include<fstream.h> #include<conio.h> class student char name[25]; int rollno; public: void readdata(); ; void student :: readdata() cout<<endl<<"enter Name "; cin>>name; cout<<endl<<"enter Rollno "; cin>>rollno; void main() char ch; int rno; fstream file; student s,t ; file.open("file.txt",ios::app ios::binary); clrscr(); while(1) s.readdata(); file.write((char *) &s, sizeof(s)); cout<<"do you Continue (Yes for Y or y) "; cin>>ch; if (ch!='y' && ch!='y') break; getch();

49 Inserting Data in Sorted File To inserted data in a sorted file, firstly its appropriate position is determined and then records in the file prior to this determined position are copied to temporary file, followed by the new record to be inserted and then the rest of the records from the file also copied. After that old file is delete and new file rename as old file. So inserting in sorted file is done with following steps.

50 Continue.. Copy the records prior to determined position to a temporary file say.. temp.dat Append the new record in temp.dat Now append the rest of record of main file into the temp.dat Delete the main file like student.dat remove( student.dat ); rename the temp.dat as student.dat as rename( temp.dat, student.dat );

51 Insert Data into Sorted file #include<fstream.h> #include<stdio.h> #include<conio.h> class student char name[25]; int rollno; public: void readdata(); int getrollno() return(rollno); ; void student :: readdata() cout<<endl<<"enter Name "; cin>>name; cout<<endl<<"enter Rollno "; cin>>rollno; int main() fstream file,outfile; student prev,next,nrec; file.open("file.txt",ios::in ios::binary); outfile.open("fil.txt",ios::out ios::binary); nrec.readdata(); clrscr();

52 CONTINUE while(1) file.read((char *) &next, sizeof(next)); if (next.getrollno()==nrec.getrollno()) cout<<endl<<"record already exitst ";getch();return 0; else if (next.getrollno()>nrec.getrollno()) outfile.write((char *) &nrec, sizeof(nrec));break; else prev=next; outfile.write((char *) &prev, sizeof(prev)); file.seekg(0); while(!file.eof()) file.read((char *) &next, sizeof(next)); if (next.getrollno()>nrec.getrollno()) outfile.write((char *) &next, sizeof(next)); remove("file.txt"); rename("fil.txt","file.txt"); getch(); return 0;

53 Deleting a Record Firstly determine the position of the record to be deleted by performing search operation. Keep copying the record other than the record to be deleted in a temporary file called temp.dat Do not copy the deleted record into the temp.dat Delete the orginal file as.. remove( student.dat ); rename the temp.dat as student.dat as rename( temp.dat, student.dat );

54 PROGRAM #include<fstream.h> #include<stdio.h> #include<conio.h> class student char name[25]; int rollno; public: void readdata(); int getrollno() return(rollno); ; void student :: readdata() cout<<endl<<"enter Rollno "; cin>>rollno; int main() fstream file,outfile; student prev,next,drec; file.open("file.txt",ios::in ios::binary); outfile.open("fi.txt",ios::out ios::binary); drec.readdata(); clrscr(); while(!file.eof()) file.read((char *) &next, sizeof(next)); if (next.getrollno()!=drec.getrollno()) outfile.write((char *) &next, sizeof(next)); file.close(); outfile.close(); remove("file.txt"); rename("fi.txt","file.txt"); getch(); return 0;

55 Modifying a Record To modify a record, the file is opened in I/O mode and an important step is performed that gives the beginning address of record being modified. After the record is modified in memory, the file pointer is once again is placed in at beginning position of this record and record is re-written.

56 PROGRAM #include<fstream.h> #include<stdio.h> #include<conio.h> class student char name[25]; int rollno; public: void modifydata(); int getrollno() return(rollno); ; void student :: modifydata() cout<<endl<<"enter Name "; cin>>name; cout<<endl<<"enter Rollno "; cin>>rollno; int main() int rno; long pos; fstream file; student mrec; file.open("file.txt",ios::in ios::out ios::binary); clrscr(); cout<<endl<<"enter Roll No to be modify "; cin>>rno; //mrec.readdata(); clrscr(); while(!file.eof()) pos=file.tellg(); file.read((char *) &mrec, sizeof(mrec)); if (mrec.getrollno()==rno) mrec.modifydata(); file.seekg(pos); file.write((char *) &mrec, sizeof(mrec)); file.close(); getch(); return 0;

57 Error Handling during File I/O During file operation, errors may occurs such as File not exist. for reading file File already exist. for writing file. End of file occurs File can not be create for less disk space File can not be open as corrupt file To check for such errors and to ensure smooth processing, C++ file stream inherits Stream-state members from ios class, that stores the information on the status of the file being currently used.

58 Flag bits eofbit 1 when end of file is encounter, 0 otherwise failbit 1 when a not fatal error I/O error has encounter 0 otherwise badbit 1 when a fatal i/o error has occured, 0 otherwise goodbit 0 value. There are several error handling functions supported by the class ios that help you read and process the status recorded in a file stream. Some error handling function are as follows

59 Error Handling Functions int bad() int eof() int fail() int good() clear() Returns non-zero value, if an invalid operation is attempted or any unrecoverable error has occured. if it is zero then possible to recover the error Returns non-zero (true value) if end of file is encountered while reading otherwise return zero (false) Returns non-zero (true) when input and output operation is failed. Returns non-zero (true) if no error has occured, This means all the above function are false Reset the error state so that further operation can be attempted.

Chapter-12 DATA FILE HANDLING

Chapter-12 DATA FILE HANDLING Chapter-12 DATA FILE HANDLING Introduction: A file is a collection of related data stored in a particular area on the disk. Programs can be designed to perform the read and write operations on these files.

More information

Unit-V File operations

Unit-V File operations Unit-V File operations What is stream? C++ IO are based on streams, which are sequence of bytes flowing in and out of the programs. A C++ stream is a flow of data into or out of a program, such as the

More information

ios ifstream fstream

ios ifstream fstream File handling in C++ In most of the real time programming problems we need to store the data permanently on some secondary storage device so that it can be used later. Whenever we have to store the data

More information

Object Oriented Programming Using C++ UNIT-3 I/O Streams

Object Oriented Programming Using C++ UNIT-3 I/O Streams File - The information / data stored under a specific name on a storage device, is called a file. Stream - It refers to a sequence of bytes. Text file - It is a file that stores information in ASCII characters.

More information

Computer programs are associated to work with files as it helps in storing data & information permanently. File - itself a bunch of bytes stored on

Computer programs are associated to work with files as it helps in storing data & information permanently. File - itself a bunch of bytes stored on Computer programs are associated to work with files as it helps in storing data & information permanently. File - itself a bunch of bytes stored on some storage devices. In C++ this is achieved through

More information

Convenient way to deal large quantities of data. Store data permanently (until file is deleted).

Convenient way to deal large quantities of data. Store data permanently (until file is deleted). FILE HANDLING Why to use Files: Convenient way to deal large quantities of data. Store data permanently (until file is deleted). Avoid typing data into program multiple times. Share data between programs.

More information

DISK FILE PROGRAM. ios. ofstream

DISK FILE PROGRAM. ios. ofstream [1] DEFINITION OF FILE A file is a bunch of bytes stored on some storage media like magnetic disk, optical disk or solid state media like pen-drive. In C++ a file, at its lowest level is interpreted simply

More information

After going through this lesson, you would be able to: store data in a file. access data record by record from the file. move pointer within the file

After going through this lesson, you would be able to: store data in a file. access data record by record from the file. move pointer within the file 16 Files 16.1 Introduction At times it is required to store data on hard disk or floppy disk in some application program. The data is stored in these devices using the concept of file. 16.2 Objectives

More information

Downloaded from

Downloaded from DATA FILE HANDLING IN C++ Key Points: Text file: A text file stores information in readable and printable form. Each line of text is terminated with an EOL (End of Line) character. Binary file: A binary

More information

DATA FILE HANDLING FILES. characters (ASCII Code) sequence of bytes, i.e. 0 s & 1 s

DATA FILE HANDLING FILES. characters (ASCII Code) sequence of bytes, i.e. 0 s & 1 s DATA FILE HANDLING The Language like C/C++ treat everything as a file, these languages treat keyboard, mouse, printer, Hard disk, Floppy disk and all other hardware as a file. In C++, a file, at its lowest

More information

Chapte t r r 9

Chapte t r r 9 Chapter 9 Session Objectives Stream Class Stream Class Hierarchy String I/O Character I/O Object I/O File Pointers and their manipulations Error handling in Files Command Line arguments OOPS WITH C++ Sahaj

More information

C++ files and streams. Lec 28-31

C++ files and streams. Lec 28-31 C++ files and streams Lec 28-31 Introduction So far, we have been using the iostream standard library, which provides cin and cout methods for reading from standard input and writing to standard output

More information

C++ does not, as a part of the language, define how data are sent out and read into the program

C++ does not, as a part of the language, define how data are sent out and read into the program Input and Output C++ does not, as a part of the language, define how data are sent out and read into the program I/O implementation is hardware dependent The input and output (I/O) are handled by the standard

More information

Consider the following example where a base class has been derived by other two classes:

Consider the following example where a base class has been derived by other two classes: Class : BCA 3rd Semester Course Code: BCA-S3-03 Course Title: Object Oriented Programming Concepts in C++ Unit IV Polymorphism The word polymorphism means having many forms. Typically, polymorphism occurs

More information

C++ Programming Lecture 10 File Processing

C++ Programming Lecture 10 File Processing C++ Programming Lecture 10 File Processing By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department Outline Introduction. The Data Hierarchy. Files and Streams. Creating a Sequential

More information

Developed By : Ms. K. M. Sanghavi

Developed By : Ms. K. M. Sanghavi Developed By : Ms. K. M. Sanghavi Designing Our Own Manipulators We can design our own manipulators for certain special purpose.the general form for creating a manipulator without any arguments is: ostream

More information

Page 1

Page 1 Virtual Functions (introduction) A virtual function is one that does not really exist but it appears real in some parts of the program. Virtual functions are advanced features of the object oriented programming

More information

Chapter 12: Advanced File Operations

Chapter 12: Advanced File Operations Chapter 12: Advanced File Operations 12.1 File Operations File Operations File: a set of data stored on a computer, often on a disk drive Programs can read from, write to files Used in many applications:

More information

C++ Binary File I/O. C++ file input and output are typically achieved by using an object of one of the following classes:

C++ Binary File I/O. C++ file input and output are typically achieved by using an object of one of the following classes: C++ Binary File I/O C++ file input and output are typically achieved by using an object of one of the following classes: ifstream for reading input only. ofstream for writing output only. fstream for reading

More information

Object Oriented Programming In C++

Object Oriented Programming In C++ C++ Question Bank Page 1 Object Oriented Programming In C++ 1741059 to 1741065 Group F Date: 31 August, 2018 CIA 3 1. Briefly describe the various forms of get() function supported by the input stream.

More information

IS 0020 Program Design and Software Tools

IS 0020 Program Design and Software Tools 1 IS 0020 Program Design and Software Tools Stack/Queue - File Processing Lecture 10 March 29, 2005 Introduction 2 Storage of data Arrays, variables are temporary Files are permanent Magnetic disk, optical

More information

Writing a Good Program. 7. Stream I/O

Writing a Good Program. 7. Stream I/O Writing a Good Program 1 Input and Output I/O implementation is hardware dependent C++ does not, as a part of the language, define how data are sent out and read into the program The input and output (I/O)

More information

Study Material for Class XII. Data File Handling

Study Material for Class XII. Data File Handling Study Material for Class XII Page 1 of 5 Data File Handling Components of C++ to be used with handling: Header s: fstream.h Classes: ifstream, ofstream, fstream File modes: in, out, in out Uses of cascaded

More information

Advanced File Operations. Review of Files. Declaration Opening Using Closing. CS SJAllan Chapter 12 2

Advanced File Operations. Review of Files. Declaration Opening Using Closing. CS SJAllan Chapter 12 2 Chapter 12 Advanced File Operations Review of Files Declaration Opening Using Closing CS 1410 - SJAllan Chapter 12 2 1 Testing for Open Errors To see if the file is opened correctly, test as follows: in.open("cust.dat");

More information

CSC 138 Structured Programming CHAPTER 4: TEXT FILE [PART 1]

CSC 138 Structured Programming CHAPTER 4: TEXT FILE [PART 1] CSC 138 Structured Programming CHAPTER 4: TEXT FILE [PART 1] LEARNING OBJECTIVES Upon completion, you should be able to: o define C++ text files o explain the benefits of using I/O file processing o explain

More information

Fall 2017 CISC/CMPE320 9/27/2017

Fall 2017 CISC/CMPE320 9/27/2017 Notices: CISC/CMPE320 Today File I/O Text, Random and Binary. Assignment 1 due next Friday at 7pm. The rest of the assignments will also be moved ahead a week. Teamwork: Let me know who the team leader

More information

File handling Basics. Lecture 7

File handling Basics. Lecture 7 File handling Basics Lecture 7 What is a File? A file is a collection of information, usually stored on a computer s disk. Information can be saved to files and then later reused. 2 File Names All files

More information

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files.

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files. C++ PROGRAMMING LANGUAGE: NAMESPACE AND MANGEMENT OF INPUT/OUTPUT WITH C++. CAAM 519, CHAPTER 15 This chapter introduces the notion of namespace. We also describe how to manage input and output with C++

More information

by Pearson Education, Inc. All Rights Reserved. 2

by Pearson Education, Inc. All Rights Reserved. 2 In Fig. 17.4, the file is to be opened for output, so an ofstream object is created. Two arguments are passed to the object s constructor the filename and the file-open mode (line 12). For an ofstream

More information

QUESTION BANK. SUBJECT CODE / Name: CS2311 OBJECT ORIENTED PROGRAMMING

QUESTION BANK. SUBJECT CODE / Name: CS2311 OBJECT ORIENTED PROGRAMMING QUESTION BANK DEPARTMENT:EEE SEMESTER: V SUBJECT CODE / Name: CS2311 OBJECT ORIENTED PROGRAMMING UNIT III PART - A (2 Marks) 1. What are the advantages of using exception handling? (AUC MAY 2013) In C++,

More information

Applications with Files, Templates

Applications with Files, Templates Files - Introduction A file is collection of data or information that has a name, called the filename. Files are stored in secondary storage devices such as floppy disks and hard disks. The main memories

More information

Lecture 9. Introduction

Lecture 9. Introduction Lecture 9 File Processing Streams Stream I/O template hierarchy Create, update, process files Sequential and random access Formatted and raw processing Namespaces Lec 9 Programming in C++ 1 Storage of

More information

Streams in C++ Stream concept. Reference information. Stream type declarations

Streams in C++ Stream concept. Reference information. Stream type declarations Stream concept A stream represent a sequence of bytes arriving, being retrieved, being stored, or being sent, in order. A stream is continuos and offer sequential access to the data. Each byte can be read

More information

Random File Access. 1. Random File Access

Random File Access. 1. Random File Access Random File Access 1. Random File Access In sequential file access, the file is read or written sequentially from the beginning. In random file access, you can skip around to various points in the file

More information

File I/O Christian Schumacher, Info1 D-MAVT 2013

File I/O Christian Schumacher, Info1 D-MAVT 2013 File I/O Christian Schumacher, chschuma@inf.ethz.ch Info1 D-MAVT 2013 Input and Output in C++ Stream objects Formatted output Writing and reading files References General Remarks I/O operations are essential

More information

Physical Files and Logical Files. Opening Files. Chap 2. Fundamental File Processing Operations. File Structures. Physical file.

Physical Files and Logical Files. Opening Files. Chap 2. Fundamental File Processing Operations. File Structures. Physical file. File Structures Physical Files and Logical Files Chap 2. Fundamental File Processing Operations Things you have to learn Physical files and logical files File processing operations: create, open, close,

More information

Fundamentals of Programming Session 27

Fundamentals of Programming Session 27 Fundamentals of Programming Session 27 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines

More information

More File IO. CIS 15 : Spring 2007

More File IO. CIS 15 : Spring 2007 More File IO CIS 15 : Spring 2007 Functionalia Office Hours Today 2 to 3pm - 0317 N (Bridges Room) HW 2 due on Sunday March 11, 11:59pm Note: Midterm is on MONDAY, March 12th Review: Thursday Today: Survey

More information

A stream is infinite. File access methods. File I/O in C++ 4. File input/output David Keil CS II 2/03. The extractor and inserter form expressions

A stream is infinite. File access methods. File I/O in C++ 4. File input/output David Keil CS II 2/03. The extractor and inserter form expressions Topic: File input/output I. Streams II. Access methods III. C++ style Input, output, random access Stream classes: ifstream, ofstream IV. C style The FILE data type Opening files Writing to, reading text

More information

Input and Output File (Files and Stream )

Input and Output File (Files and Stream ) Input and Output File (Files and Stream ) BITE 1513 Computer Game Programming Week 14 Scope Describe the fundamentals of input & output files. Use data files for input & output purposes. Files Normally,

More information

Chapter 14 Sequential Access Files

Chapter 14 Sequential Access Files Chapter 14 Sequential Access Files Objectives Create file objects Open a sequential access file Determine whether a sequential access file was opened successfully Write data to a sequential access file

More information

Module 11 The C++ I/O System

Module 11 The C++ I/O System Table of Contents Module 11 The C++ I/O System CRITICAL SKILL 11.1: Understand I/O streams... 2 CRITICAL SKILL 11.2: Know the I/O class hierarchy... 3 CRITICAL SKILL 11.3: Overload the > operators...

More information

Advanced I/O Concepts

Advanced I/O Concepts Advanced Object Oriented Programming Advanced I/O Concepts Seokhee Jeon Department of Computer Engineering Kyung Hee University jeon@khu.ac.kr 1 1 Streams Diversity of input sources or output destinations

More information

Object Oriented Programming CS250

Object Oriented Programming CS250 Object Oriented Programming CS250 Abas Computer Science Dept, Faculty of Computers & Informatics, Zagazig University arabas@zu.edu.eg http://www.arsaliem.faculty.zu.edu.eg Object Oriented Programming Principles

More information

Chapter 8 File Processing

Chapter 8 File Processing Chapter 8 File Processing Outline 1 Introduction 2 The Data Hierarchy 3 Files and Streams 4 Creating a Sequential Access File 5 Reading Data from a Sequential Access File 6 Updating Sequential Access Files

More information

All About: File I/O in C++ By Ilia Yordanov, ; C++ Resources

All About: File I/O in C++ By Ilia Yordanov,  ; C++ Resources All About: File I/O in C++ By Ilia Yordanov, loobian@cpp-home.com www.cpp-home.com ; C++ Resources This tutorial may not be republished without a written permission from the author! Introduction This tutorial

More information

CS Programming2 1 st Semester H Sheet # 8 File Processing. Princess Nora University College of Computer and Information Sciences

CS Programming2 1 st Semester H Sheet # 8 File Processing. Princess Nora University College of Computer and Information Sciences Princess Nora University College of Computer and Information Sciences CS 142-341 Programming2 1 st Semester 1434-1435 H Sheet # 8 File Processing Question#1 Write line of code to do the following: 1- Open

More information

BITG 1113: Files and Stream LECTURE 10

BITG 1113: Files and Stream LECTURE 10 BITG 1113: Files and Stream LECTURE 10 1 LEARNING OUTCOMES At the end of this lecture, you should be able to: 1. Describe the fundamentals of input & output files. 2. Use data files for input & output

More information

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2013

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2013 Q.2 a. Discuss the fundamental features of the object oriented programming. The fundamentals features of the OOPs are the following: (i) Encapsulation: It is a mechanism that associates the code and data

More information

Stream States. Formatted I/O

Stream States. Formatted I/O C++ Input and Output * the standard C++ library has a collection of classes that can be used for input and output * most of these classes are based on a stream abstraction, the input or output device is

More information

System Design and Programming II

System Design and Programming II System Design and Programming II CSCI 194 Section 01 CRN: 10968 Fall 2017 David L. Sylvester, Sr., Assistant Professor Chapter 12 Advanced File Operation File Operations A file is a collection of data

More information

Module C++ I/O System Basics

Module C++ I/O System Basics 1 Module - 36 C++ I/O System Basics Table of Contents 1. Introduction 2. Stream classes of C++ 3. Predefined Standard Input/Output Streams 4. Functions of class 5. Functions of class

More information

Streams contd. Text: Chapter12, Big C++

Streams contd. Text: Chapter12, Big C++ Streams contd pm_jat@daiict.ac.in Text: Chapter12, Big C++ Streams Objects are Abstracted Wrapper around input/output source/destinations Steps in reading/writing streams- Open: Establish connection between

More information

High Order Thinking Skill Questions Subject : Computer Science Class: XII 1 Mark Questions Programming in C++ 1. Observe the program segment carefully and answer the question that follows: int getitem_no(

More information

CSc Introduc/on to Compu/ng. Lecture 19 Edgardo Molina Fall 2011 City College of New York

CSc Introduc/on to Compu/ng. Lecture 19 Edgardo Molina Fall 2011 City College of New York CSc 10200 Introduc/on to Compu/ng Lecture 19 Edgardo Molina Fall 2011 City College of New York 18 Standard Device Files Logical file object: Stream that connects a file of logically related data to a program

More information

Text File I/O. #include <iostream> #include <fstream> using namespace std; int main() {

Text File I/O. #include <iostream> #include <fstream> using namespace std; int main() { Text File I/O We can use essentially the same techniques we ve been using to input from the keyboard and output to the screen and just apply them to files instead. If you want to prepare input data ahead,

More information

UNIT V FILE HANDLING

UNIT V FILE HANDLING UNIT V CONTENTS: Streams and formatted I/O I/O manipulators File handling Random access Object serialization Namespaces Std namespace ANSI String Objects Standard template library FILE HANDLING Streams:

More information

Data File Handling FILL IN THE BLANKS EACH QUESTION CARRY 1 MARK

Data File Handling FILL IN THE BLANKS EACH QUESTION CARRY 1 MARK Data File Handling FILL IN THE BLANKS EACH QUESTION CARRY 1 MARK 1.. Observe the program segment given below carefully, and answer the question that follows: class Labrecord int Expno; char Expriment[20];

More information

Week 3: File I/O and Formatting 3.7 Formatting Output

Week 3: File I/O and Formatting 3.7 Formatting Output Week 3: File I/O and Formatting 3.7 Formatting Output Formatting: the way a value is printed: Gaddis: 3.7, 3.8, 5.11 CS 1428 Fall 2014 Jill Seaman spacing decimal points, fractional values, number of digits

More information

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class C++ IO C++ IO All I/O is in essence, done one character at a time For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Concept: I/O operations act on streams

More information

C++ How to Program 14.6

C++ How to Program 14.6 C++ How to Program 14.6 14.6 Random-Access Files pg.611-pg.612 -Unlike sequential files, R.A. files are instant-access applications. Any transaction-processing system. Requiring rapid access to specific

More information

Chapter 12 File Operations. Starting Out with C++, 3 rd Edition

Chapter 12 File Operations. Starting Out with C++, 3 rd Edition Chapter 12 File Operations 1 12.1 What is a File? A file is a collection on information, usually stored on a computer s disk. Information can be saved to files and then later reused. 2 12.2 File Names

More information

by Pearson Education, Inc. All Rights Reserved. 2

by Pearson Education, Inc. All Rights Reserved. 2 Data that is formatted and written to a sequential file as shown in Section 17.4 cannot be modified without the risk of destroying other data in the file. For example, if the name White needs to be changed

More information

CS2141 Software Development using C/C++ Stream I/O

CS2141 Software Development using C/C++ Stream I/O CS2141 Software Development using C/C++ Stream I/O iostream Two libraries can be used for input and output: stdio and iostream The iostream library is newer and better: It is object oriented It can make

More information

VuZs Team's Work. CS201 Spring Solved by vuzs Team with Reference Written by Administrator Wednesday, 19 May :52

VuZs Team's Work. CS201 Spring Solved by vuzs Team with Reference Written by Administrator Wednesday, 19 May :52 CS201 Spring2009 5 Solved by vuzs Team with Reference Written by Administrator Wednesday, 19 May 2010 17:52 MIDTERM EXAMINATION Spring 2009 CS201- Introduction to Programming Shared & Solved by vuzs Team

More information

by Pearson Education, Inc. All Rights Reserved. 2

by Pearson Education, Inc. All Rights Reserved. 2 The C++ standard libraries provide an extensive set of input/output capabilities. C++ uses type-safe I/O. Each I/O operation is executed in a manner sensitive to the data type. If an I/O member function

More information

UEE1303(1070) S 12 Object-Oriented Programming in C++

UEE1303(1070) S 12 Object-Oriented Programming in C++ Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1303(1070) S 12 Object-Oriented Programming in C++ Lecture 06: Streams and File Input/Output I/O stream istream and ostream member

More information

I/O Streams and Standard I/O Devices (cont d.)

I/O Streams and Standard I/O Devices (cont d.) Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore how to read data from the standard input device Learn how to use predefined

More information

File Operations. Lecture 16 COP 3014 Spring April 18, 2018

File Operations. Lecture 16 COP 3014 Spring April 18, 2018 File Operations Lecture 16 COP 3014 Spring 2018 April 18, 2018 Input/Ouput to and from files File input and file output is an essential in programming. Most software involves more than keyboard input and

More information

File I/O. File Names and Types. I/O Streams. Stream Extraction and Insertion. A file name should reflect its contents

File I/O. File Names and Types. I/O Streams. Stream Extraction and Insertion. A file name should reflect its contents File I/O 1 File Names and Types A file name should reflect its contents Payroll.dat Students.txt Grades.txt A file s extension indicates the kind of data the file holds.dat,.txt general program input or

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Course Title: Object Oriented Programming Full Marks: 60 20 20 Course No: CSC161 Pass Marks: 24 8 8 Nature of Course: Theory Lab Credit Hrs: 3 Semester: II Course Description:

More information

Fundamental File Processing Operations 2. Fundamental File Processing Operations

Fundamental File Processing Operations 2. Fundamental File Processing Operations 2 Fundamental File Processing Operations Copyright 2004, Binnur Kurt Content Sample programs for file manipulation Physical files and logical files Opening and closing files Reading from files and writing

More information

(1)Given a binary file PHONE.DAT, containing records of the following structure type class Phonlist { char Name[20]; char Address[30]; char

(1)Given a binary file PHONE.DAT, containing records of the following structure type class Phonlist { char Name[20]; char Address[30]; char (1)Given a binary file PHONE.DAT, containing records of the following structure type class Phonlist char Name[20]; char Address[30]; char AreaCode[5]; char PhoneNo[15]; Public: void Register(); void Show();

More information

Physics 6720 I/O Methods October 30, C++ and Unix I/O Streams

Physics 6720 I/O Methods October 30, C++ and Unix I/O Streams Physics 6720 I/O Methods October 30, 2002 We have been using cin and cout to handle input from the keyboard and output to the screen. In these notes we discuss further useful capabilities of these standard

More information

Generate error the C++ way

Generate error the C++ way Reference informa9on Lecture 3 Stream I/O Consult reference for complete informa9on! UNIX man- pages (available on exam): man topic man istream man ostream ios, basic_string, stringstream, ctype, numeric_limits

More information

ENGI 1020 Introduction to Computer Programming R E Z A S H A H I D I J U L Y 2 6,

ENGI 1020 Introduction to Computer Programming R E Z A S H A H I D I J U L Y 2 6, ENGI 1020 Introduction to Computer Programming R E Z A S H A H I D I J U L Y 2 6, 2 0 1 0 Streams and files We have already talked about the standard input stream (cin), and the standard output stream

More information

File Processing in C++

File Processing in C++ File Processing in C++ Data Representation in Memory Record: A subdivision of a file, containing data related to a single entity. Field : A subdivision of a record containing a single attribute of the

More information

CHAPTER-7 Data File Handling

CHAPTER-7 Data File Handling CHAPTER-7 Data File Handling VERY SHORT/SHORT ANSWER QUESTIONS 1. What are input and output streams? What is the significance of fstream.h file? Ans. Input stream: The stream that supplies data to the

More information

CS201 Latest Solved MCQs

CS201 Latest Solved MCQs Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Quiz Start Time: 09:34 PM Time Left 82 sec(s) Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

Object Oriented Pragramming (22316)

Object Oriented Pragramming (22316) Chapter 1 Principles of Object Oriented Programming (14 Marks) Q1. Give Characteristics of object oriented programming? Or Give features of object oriented programming? Ans: 1. Emphasis (focus) is on data

More information

Programming II with C++ (CSNB244) Lab 10. Topics: Files and Stream

Programming II with C++ (CSNB244) Lab 10. Topics: Files and Stream Topics: Files and Stream In this lab session, you will learn very basic and most common I/O operations required for C++ programming. The second part of this tutorial will teach you how to read and write

More information

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2014

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2014 Q.2 a. Differentiate between: (i) C and C++ (3) (ii) Insertion and Extraction operator (iii) Polymorphism and Abstraction (iv) Source File and Object File (v) Bitwise and Logical operator Answer: (i) C

More information

Chapter 3 - Notes Input/Output

Chapter 3 - Notes Input/Output Chapter 3 - Notes Input/Output I. I/O Streams and Standard I/O Devices A. I/O Background 1. Stream of Bytes: A sequence of bytes from the source to the destination. 2. 2 Types of Streams: i. Input Stream:

More information

Introduction. Lecture 5 Files and Streams FILE * FILE *

Introduction. Lecture 5 Files and Streams FILE * FILE * Introduction Lecture Files and Streams C programs can store results & information permanently on disk using file handling functions These functions let you write either text or binary data to a file, and

More information

SUBMITTED AS A PART OF C.B.S.E. CURRICULUM FOR THE YEAR

SUBMITTED AS A PART OF C.B.S.E. CURRICULUM FOR THE YEAR SUBMITTED AS A PART OF C.B.S.E. CURRICULUM FOR THE YEAR 2008-09 CONTENTS CERTIFICATE ACKNOWLEDGEMENT PROJECT PREAMBLE PROJECT STUDY ALGORITHM SOURCE CODE OUTPUT CERTIFICATE This is to certify that, Roll

More information

Lecture 5 Files and Streams

Lecture 5 Files and Streams Lecture 5 Files and Streams Introduction C programs can store results & information permanently on disk using file handling functions These functions let you write either text or binary data to a file,

More information

SECTION A (15 MARKS) Answer ALL Questions. Each Question carries ONE Mark. 1 (a) Choose the correct answer: (10 Marks)

SECTION A (15 MARKS) Answer ALL Questions. Each Question carries ONE Mark. 1 (a) Choose the correct answer: (10 Marks) SECTION A (15 MARKS) Answer ALL Questions. Each Question carries ONE Mark. 1 (a) Choose the correct answer: (10 Marks) 1. The function is used to reduce function call a. Overloading b. Inline c. Recursive

More information

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University) Estd: 1994 JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli - 621014 (An approved by AICTE and Affiliated to Anna University) ISO 9001:2000 Certified Subject Code & Name : CS 1202

More information

Fig: iostream class hierarchy

Fig: iostream class hierarchy Unit 6: C++ IO Systems ================== Streams: Θ A stream is a logical device that either produces or consumes information. Θ A stream is linked to a physical device by the I/O system. Θ All streams

More information

SHORT REVIEW OF CS TOPICS RANDOM NUMBERS (2 MARKS) which generates a random number in the range of 0 to n-1. For example;

SHORT REVIEW OF CS TOPICS RANDOM NUMBERS (2 MARKS) which generates a random number in the range of 0 to n-1. For example; SHORT REVIEW OF CS TOPICS RANDOM NUMBERS (2 MARKS) Generating Random Numbers The key function in generating random numbers is; int random (int n); which generates a random number in the range of 0 to n-1.

More information

SOS HERMANN GMEINER SCHOOL QUESTION BANK XII COMPUTER SCIENCE Unit-Wise Marks and Period Distribution

SOS HERMANN GMEINER SCHOOL QUESTION BANK XII COMPUTER SCIENCE Unit-Wise Marks and Period Distribution SOS HERMANN GMEINER SCHOOL QUESTION BANK XII COMPUTER SCIENCE Unit-Wise Marks and Period Distribution Unit No. Unit Name Marks. 2. 3. 4. 5. PROGRAMMING IN C++ DATA STRUCTURE DATABASE AND SQL BOOLEAN ALGEBRA

More information

Streams - Object input and output in C++

Streams - Object input and output in C++ Streams - Object input and output in C++ Dr. Donald Davendra Ph.D. Department of Computing Science, FEI VSB-TU Ostrava Dr. Donald Davendra Ph.D. (Department of Computing Streams - Object Science, input

More information

JB Academy, Faizabad Half Yearly Examination Subject: Computer Science (083) Class XII

JB Academy, Faizabad Half Yearly Examination Subject: Computer Science (083) Class XII JB Academy, Faizabad Half Yearly Examination - 2017-18 Subject: Computer Science (083) Class XII Time: 3 Hours Max. Marks: 70 Instructions: i) All questions are compulsory and so attempt all. ii) Programming

More information

Files and Streams. 1 P a g e

Files and Streams. 1 P a g e Files and Streams Introduction : When a large amount of data is to be handled in such situations floppy disk or hard disk are needed to store the data. The data is stored in these devices using the concept

More information

Chapter 12. Streams and File I/O. Copyright 2010 Pearson Addison-Wesley. All rights reserved

Chapter 12. Streams and File I/O. Copyright 2010 Pearson Addison-Wesley. All rights reserved Chapter 12 Streams and File I/O Copyright 2010 Pearson Addison-Wesley. All rights reserved Learning Objectives I/O Streams File I/O Character I/O Tools for Stream I/O File names as input Formatting output,

More information

COMP322 - Introduction to C++

COMP322 - Introduction to C++ COMP322 - Introduction to C++ Lecture 05 - I/O using the standard library, stl containers, stl algorithms Dan Pomerantz School of Computer Science 5 February 2013 Basic I/O in C++ Recall that in C, we

More information

This can be thrown by dynamic_cast. This is useful device to handle unexpected exceptions in a C++ program

This can be thrown by dynamic_cast. This is useful device to handle unexpected exceptions in a C++ program Abstract class Exception handling - Standard libraries - Generic Programming - templates class template - function template STL containers iterators function adaptors allocators -Parameterizing the class

More information

Lecture 3 The character, string data Types Files

Lecture 3 The character, string data Types Files Lecture 3 The character, string data Types Files The smallest integral data type Used for single characters: letters, digits, and special symbols Each character is enclosed in single quotes 'A', 'a', '0',

More information

Chapter 12. Streams and File I/O. Copyright 2016 Pearson, Inc. All rights reserved.

Chapter 12. Streams and File I/O. Copyright 2016 Pearson, Inc. All rights reserved. Chapter 12 Streams and File I/O Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives I/O Streams File I/O Character I/O Tools for Stream I/O File names as input Formatting output, flag

More information