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 : Define Fetch-execute cycle

    Fetch-execute cycle: The simple set of steps which are endlessly recurring by a computer's Central Processing Unit for each and every program instruction: `Fetch the next instruction suggested by the program counter,' `update the program counter to pa

  • Q : Define the term Identifier Define the

    Define the term Identifier: It is a programmer-defined name for a method, variable, class and interface.

  • Q : Bank accounts Assignment &Code in JAVA

    Java Assignment Scenario:  Bank accounts Data structures need to be modelled with UML then created in Java

  • Q : What is SLAM SLAM is a Microsoft

    SLAM is a Microsoft project that blurs the line between static analysis and model checking and deductive reasoning. The main goal of SLAM is to check temporal safety properties of C programs (it actually checks that a program correctly uses the interf

  • Q : What is an Unchecked exception

    Unchecked exception: An exception for which it is not needed to give a local try statement or to propagate through a throws clause stated in the method header. An exception which is not handled will cause program annihilation when it is thrown.

  • Q : Explain Operator Explain Operator with

    Explain Operator with their types and examples?

  • Q : Describe Multiple-boot options

    Multiple-boot options: The hardware configurations of several computers are capable to run various operating system and window manager combinations. A few systems permit a user to select which combination they wish to utilize during a specific session

  • Q : Explain Untyped Allocations Untyped

    Untyped Allocations: In C/C++ untyped allocations such as malloc, calloc, and realloc can easily be used to create overlays, which again require translation overhead to keep the corresponding non-overlaid objects consistent.

    Q : Define Multiple Inheritance Multiple

    Multiple Inheritance: In C++, multiple-inheritance occurs when a class inherits from more than one parent. For example: 524_mult</span></p>
                                        <!-- /comment-box -->
                                        <div class=

    Q : ID of TC Trustcenter Publisher and

    For how long are ID of TC Trustcenter Publisher and certificates of developer valid?

©TutorsGlobe All rights reserved 2022-2023.