WRITING TO FILE

WRITING function is used to write to the file which is one of the basic need of our program. This function is expected to be used every time we change anything in the data-set which is first opened in append mode in our program.



In the above part of code, in void writing() first we open our file and then check for error in opening the file. If there is no error in opening the file then we proceed for the further code.



After checking for availability of file, we write the data stored in our array yash to the file.
To do so, a variable k is initialized to 0 which is incremented till the top which tells the end of the array yash i.e. taking all the entries.

file.setf(ios::left,ios::adjustfield);
file.width(20);
                       Above to lines are used to align text to left side and first attribute of each line have reserved 20 character space fir itself (just for the sake of alignment) as shown below.

After name there is 16 character space is left.
Similarly all the attributes are added to file.

After all data is written, k is incremented and while loop continues for every array element of yash.
and when top is reached file is closed.
In the end if there is an error opening the file we will get an message saying "File not opened".


Comments

  1. Nicely took all the points, informative πŸ‘

    ReplyDelete

Post a Comment

Popular posts from this blog

SEARCHING

ORDER BY PART-2

GROUP BY