File handling functions in C++


File management is required everywhere. C++ makes its own database file in machine language and we use it according to our own convenience. Here all data input by the user is treated like string. Sometimes we call it stream or flow of data.

First of all we know few functions which are used in file handling.

These are basicĀ File handling functions in C++

open

Use of this function is to open many files to be used as continuous stream object. For example object.open(“filename”);

close

It is use for closing a file. For example object.close()

getline

This function access one line data. For example object.getline(Line, Size);

eof()

Use of this function is to know that content pointer inside a file is in last of the of the file. For example if(obj.eof())

bof

This is used to know that whether content pointer inside the file is in starting of data. For example if(obj.bof())

seekg()

The work of this function is to bring get pointer to a specific location. For example obj.seekg(5)

seekp()

This function brings put pointer to a specific location. For example obj.seekp(10)

tellg()

It brings get pointer to the correct location.

tellp()

It brings put pointer to the correct location.

read()

This function read data in binary format.

write()

This function write data in binary format.

sizeof()

It tells the size of data to be used.

fail()

It returns true if input or output operation in a file fails.

itstream

This type of object helps in reading data from file.

ofstream

This type of object helps in writing data in file.

fstream

This type of object helps in reading or writing from object file.

Related Posts

Leave a Comment