Advantage and disadvantage of cell phones

This essay has been submitted by a student. This is not an example of the work written by professional essay writers.

18 April 2016

Remember! This is just a sample.

You can get your custom paper by one of our expert writers.

Get custom essay

95 writers online

Before getting into this section, it is recommended that you have a proper understanding of Text file and Binary File. If any of both seems strange to you we give short information about these files:- Text file. The text file stores the data in ASCII character. Each line of text is terminated with a special character known as EOL (End of Line) character or delimiter character in text files. When this EOL character is read or written, certain internal translations take place. Binary file. The Binary File stores the data in the same format as it is held in memory. No delimiters are used for a line and no translations occur here in binary files. The following stream classes can be used in C++ to working with files: ofstream: Write on files ifstream: Read from files fstream: Both read and write from/to files.

To open a file we use open() command as following: ofstream cppfile;“filename”,mode); In the above line: ofstream cppfile:
By using ofstream we declared a file variable cppfile who used to access file. (“filename”,mode): You can see that we use the file variablecppfile with open() to open a file. filename is a file which to be open and modecan be the following : File mode

Append to end of file
go to end of file on opening
file open in binary mode
open file for reading only
open file for writing only
open fails if the file does not exist
open fails if the file already exist
delete the contents of the file if it exist

When we use two mode at a time we have to use operator OR (|) between mode. For example, if we want to open the file example.dat in binary mode to add data we could do it by the following: fstream myfile; (“example.dat”, ios::out | ios::app | ios::binary);
If you have opened any file then you must close the opened file by following command: myfile.close();

put() Function :
The function put() writes a single character to the associated stream.
get() Function :
Similarly, the function get() reads a single character form the associated stream. example :

write() function :
write() function write blocks of binary data.
read() Function :
read() function read blocks of binary data.
myfile.write((char *)&obj, sizeof(obj)); *)&obj, sizeof(obj));


Returns true if a reading or writing operation fails,
Returns true if a file open for reading has reached the end. bad()
Returns true if an invalid operation are attempted, for example if you are trying to write to a file that is not opened for writing operation or that file has no space left. good()
Returns true if no error has occurred.

All Input Output streams objects have at least one internal stream pointer: ifstream is a just like istream, and it has a get pointer that points to the element to be read in the next input operation. ofstream is a just like ostream, and it has a put pointer that points to the location where the next element has to be written. fstream, inherits the get and the put pointers, from iostream.

The above internal stream pointers can be manipulated using the following member functions:
moves get pointer(input) to a specified location
moves put pointer (output) to a specified location
gives the current position of the get pointer
gives the current position of the put pointer

The other prototype for above functions is:

seekg(offset, ref_position );
seekp(offset, ref_position );

The parameter offset represents the number of bytes the file pointer is to be moved from the location specified by the parameter ref_position. Theref_position takes one of the following three constants defined in the ios class.

ios::beg start of the file
ios::cur current position of the pointer
ios::end end of the file

Data Handling with Text file in C++

Example to write in a text file

int main()
ofstream myfile;“example.txt”);

Cite this page

Advantage and disadvantage of cell phones. (18 April 2016). Retrieved from

"Advantage and disadvantage of cell phones" StudyScroll, 18 April 2016,

StudyScroll. (2016). Advantage and disadvantage of cell phones [Online]. Available at: [Accessed: 25 June, 2022]

"Advantage and disadvantage of cell phones" StudyScroll, Apr 18, 2016. Accessed Jun 25, 2022.

"Advantage and disadvantage of cell phones" StudyScroll, Apr 18, 2016.

"Advantage and disadvantage of cell phones" StudyScroll, 18-Apr-2016. [Online]. Available: [Accessed: 25-Jun-2022]

StudyScroll. (2016). Advantage and disadvantage of cell phones. [Online]. Available at: [Accessed: 25-Jun-2022]

Don't use plagiarized sources. Get your custom essay..

get custom paper

We use cookies to personalyze your web-site experience. By continuing we’ll assume you board with our cookie policy.