Create an f stream to a binary file


Problem:

Question 1: Write a short C++ program that opens a text file, write 2 integers to it, closes it, does the same with a binary file (open, write 2 integers to, and close), then opens the text file, read integers from into two different variables, and print them to the screen, and then does the same with the binary file. Basically, use the usual >>, << for text files, and read () and write () for binary files. For read () and write () you can use the size of() function to get the size of an integer. Remember; use different set of variables when reading from the files so you know that the values were actually read in.

Question 2: Create an fstream to a binary file that you can both write to and read from. Write 5 objects of your class to your binary file. Then see if you can read them all back in order and print them to the screen. Next, see if you can retrieve the third object directly from the file by using seekg() and an offset from the file beginning of 2 object size.

 

Please show the coding of the programs and explain it using comments.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Create an f stream to a binary file
Reference No:- TGS0892803

Expected delivery within 24 Hours