What are different file stream classes? Expain the syntax of opening the file in read and write mode .can while (fin) be replaced with if (fin1.eof()!=0) to process the file? Justify
In C++, files are mainly dealt by using three classes fstream, ifstream, ofstream.
ptr = fopen("fileopen","mode");
where "fileopen" is the path to the file on your device, "mode" is mode in which file will be opened("r" to open in READ mode and "w" - in WRITE mode)
eof () is a member of the fstream class that returns true or false depending on whether the end of file (eof) of the file you are reading has been reached. Thus, as long as eof () returns 0, it means that the end of file has not been reached and the loop continues to run, but when eof () returns 1, the end of file is reached and the loop ends.
The while (fin) loop is introduced because fin actually returns the value of an error flag variable within a class object fin, which is set to 0 when any function, such as reading, writing, or opening, fails. Thus, the loop runs as long as the read function inside the loop is running.
Comments
Leave a comment