C++ FILE STREAMS A Stream is a sequence of bytes. It acts either as a source from which input data can be got or a destinations to which the output data can be sent.
Disk File Memory INPUT STREAM OUTPUT STREAM Program 2/11/2022 S KIRAN PGT(COMP) KVCLRI
STREAMS OUTPUT STREAM INPUT/OUTPUT STREAM 2/11/2022 S KIRAN PGT(COMP) KVCLRI
FILE MODE FILE TEXT MODE 2/11/2022 BINARY MODE S KIRAN PGT(COMP) KVCLRI
• IN TEXT MODE – Stores information n ASCII, each line terminates with a EOL character, • Internal Translation takes place when data is read or written • IN BINARY MODE – Stores information in the same format in which it is stored in the memory. • No EOL character • No translation • Faster and Easier to Read and Write 2/11/2022 S KIRAN PGT(COMP) KVCLRI
OPENING A FILE USING CONSTRUCTOR USING OPEN() 2/11/2022 • It is preferred for managing single file • It is used for managing multiple file with same stream S KIRAN PGT(COMP) KVCLRI
Reading and Writing Class Objects Class student { char name[30]; float marks; public: void getdata(); void putdata(); }; 2/11/2022 S KIRAN PGT(COMP) KVCLRI
for(int i=0; i<10; i++) { s[i]. getdata(); file. write((char*)&s[i], sizeof(s[i])); } file. seekg(0); cout<<“The Contents of the file are “; for(int i=0; i<10; i++) { file. read(((char*)&s[i], sizeof(s[i])); s[i]. putdata(); } file. close(); 2/11/2022 S KIRAN PGT(COMP) KVCLRI