File:Basic informations and funtions,Input/output procedures through C++



So far in C++ we have come across iostream headers for input output purposes defining cin, cout functions. But as mentioned previously those input values were temporary and couldn’t be used for future access. But it is never so that we cannot store the inputted values for future access in fact the can be stored as a whole sort of document. The procedure is popularly known as files one can define a file, can be a text document also. As we declared a separate header file for input output purposes in the previous section in the same way we need to declare a header file to use a file. The header file is better known as fstream. Basically fstream function is a predefined class type and hence its object needed to be defined in the main function as follows:
Void main(){
Fstream f1;
F1.open(ios::out);
………
}
The above mentioned file is to open a predefined file. Where open() is a function used to open a file. It’s a keyword one can mention to. Similarly, to read a file we need to use the keyword read(). Files lead to a lot of memory leaks and so we need to close this class. Again for it we need to use a different keyword that is close().Files are mainly used to store information inputted by user in a document form. As the data is inputted through the keyboard it reaches the memory from the memory it moves to the file it is to be stored in. When the value is called to be displayed the vice versa process takes place that is the value first moves to the memory then the memory directs it to the monitor or the display the data to user. This includes a lot of background process one of the most vital one is conversion high level language to machine level language when user gives the input and the vice versa that is machine level to high level when user asks for display. A very good example of abstraction of data. A file can be opened in many forms, some of them are as follows:
      1.       ios::in->to open a file in input mode
      2.       ios::out->to open a file in output mode
      3.       ios::binary->to open a file in binary mode
      4.       ios::ate->to set the pointer of the file at the end
      5.       ios::app->it will write the output in the file from the end of the data without deleting the previous ones
      6.       ios::trunc->it will delete all previous data present in file and rewrite in it

Share this

Related Posts

Previous
« Prev Post