A Stream is generally referred to flow of data. Different streams are used to represent different kinds of data flow
ios
istream iostream ifstream ostream
fstream
ofstream
2)
3) Ofstream :
ofstream
fstream
Every object of type ofstream uses a filename to store information in that file.
Ifstream :
To read the contents from a file we must create an object of class ifstream.
Opening a File
The Open() function is used to open different files that uses the same stream object.
Syntax : open(filename, file mode);
File Mode
ios :: in ios :: out ios :: app
ios :: ate
Description
Open file for reading Open file for writing Open file for reading and/or writing the data at the end of file (append)
Erase the file before reading or writing(Truncated)
ios :: nocreate
ios :: no replace
ios :: binary
Closing a File
To close a file, the member function close() must be used. It takes no parameters and returns no value.
Syntax : close();
Detecting End-Of-File
It is necessary for preventing any attempt to read data from the file. Syntax : eof()
write Function
It is used for displaying a text in a line until it encounters a \n characters. Syntax : cout.write(char*,size);
Result
Enter any String : India is My Country
India is My Country