Hasil (
Bahasa Indonesia) 1:
[Salinan]Disalin!
Whenever a modification of file contents is required is, it is necessary to reach the spot wherethe modification is desired. A file is sequence of bytes with the first byte as the 0 th byte. For areaching a particular spot you have to know how many bytes it is away from the beginning offile or from the end of file in a backward motion. A file pointer points to a position in a file,which is determined by the offset (number of bytes) from the beginning or from the end. Youwould have understood that file pointer is different from the pointers we have used in arrays andclasses in which case the pointer value is the address (the byte number of the start byte) in allocatedmemory in RAM. The file pointer is not the address, it is simply an offset in bytes from thebeginning of file or end or from current position. When a file is opened in the read mode thefile pointer is positioned at the beginning of the file. Similarly when file is opened in write modethe pointer is again at the beginning of file because opening in write mode deletes the existingcontents of the file, so the pointer is positioned at the beginning of file. In case of append mode(ios::app) the pointer is at the end of file ready to add the additional data. In the append modethe existing contents remain intact. The Figure 19.5 illustrates the pointer positions for read, writeand append modes.Two pointers, i.e. input pointer and output pointer are associated with every file. The inputpointer which is used for reading the file from a particular location is called get pointer. Theoutput pointer which is used for writing in the file is called put pointer. The four functions listedin Table 19.7 are used to shift the pointer to a location in the file.
Sedang diterjemahkan, harap tunggu..