--%>

Reads and writes functions

To accumulate or recover data in binary form, the member functions write () or read () can be utilized. Unlike put () and get (), the write () and read () functions access data in binary arrangement. In binary format, the data representation in the system and in the file is similar. The number of bytes required to represent an integer in text from is proportional to its magnitude, where as in binary form the size is always fixed irrespective to its magnitude. Thus the binary form is more accurate, and provides faster access to the file because no conversion is required while performing read or writes. The read () and write () functions have the subsequent syntax: -

In file. Read ((char *) & variable, size of (variable));

Out file. Write ((char *) & variable, size of (variable));

The first parameter is a pointer to a memory location at which the data retrieved from the file is to be stored in case of read () and address at which data is to be written when retrieved from a file in case of write (). The second parameter indicates the number of bytes to be transferred and the programme give below illustrates the certain and manipulation of binary files.

Use of write and read member of file steams:

# include < f stream. h >

   Void main ()

{

Int num 1 = 530;

Float num 2 = 1050.25;

// open file in write binary mode, write integer and close.

Of stream out _ file (num. Binary", ios : : binary);

 Out _ file. Write ((char *) & num 1, size of (num 1));

 Out _ file. Write ((char *) & num 2, size of (num 2));

Out _ file. Close ();

If stream in _ file ("number. Binary", ios : : binary);

In _ file. Read ((char *) & num 1, size of Int));

In _ file. Read ((char *) & num 1, size of (num 2));

  Cout << num 1 << " " << num 2 << end 1;

In _ file . close ();

}

   Related Questions in Programming Languages

  • Q : Functions of states of the

    Mention the different states of the XMLHttpRequest an dalso describe their functions.

  • Q : Command to recognize type of file

    Specify the command which is used to recognize the type of file?

  • Q : State the term Web application State

    State the term Web application?

  • Q : Explain the way to start a Web Service

    Explain the way to start a Web Service.

  • Q : Double clock signal in synchronous

    Describes the cases where you need to double clock a signal before presenting this to a synchronous state machine?

  • Q : What is no-arg constructor no-arg

    no-arg constructor: It is a constructor which takes no arguments. By default, each and every class without an explicit constructor has a default no-arg constructor with the public access. Its role is entirely to invoke the no-arg constructor of the in

  • Q : ERD What is the meaning ofDerive the

    What is the meaning ofDerive the department and staff relations from the following ERD.

  • Q : What is sticky bit Explain the sticky

    Explain the sticky bit?

  • Q : Determining group ID of new file

    Explain various options available in order to determine the group ID of new file?

  • Q : Reference variables Reference variable

    Discover Q & A

    Leading Solution Library
    Avail More Than 1443641 Solved problems, classrooms assignments, textbook's solutions, for quick Downloads
    No hassle, Instant Access
    Start Discovering

    18,76,764

    1933098
    Asked

    3,689

    Active Tutors

    1443641

    Questions
    Answered

    Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!

    Submit Assignment

    ©TutorsGlobe All rights reserved 2022-2023.