--%>

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 : What are the tools require writing

    What are the tools require writing XHTML documents?

  • Q : Asynchronous and synchronous postback

    Differeniate asynchronous postback and synchronous postback?

  • Q : Define the term Micro- Processor Define

    Define the term Micro- Processor.

  • Q : Program is prone to deadlock when

      Give a brief introduction about the operation of your program and show that you understand the idea behind threads and mutual exclusion variable. Why do we need to use mutual exclusion to control the access of the three global variables? What is the potential p

  • Q : Define the term Mutual recursion Define

    Define the term Mutual recursion: Recursion which outcomes from two methods calling one other recursively.

  • Q : Define Assembler Assembler : The

    Assembler: The program employed to translate a program which is written in assembly language into the binary form of a specific instruction set.

  • Q : Write a program that enters some text

    Write a program that enters some text into a char string called char text[100] and does the following: a) Calls a function called void vowels(char text[]) that prints out how many times each vowel (a/A, e/E, I/i, O/o, U/u) was foun

  • Q : What is Character Set What is Character

    What is Character Set. Briefly explain it?

  • Q : What is an Exception handler Exception

    Exception handler: It is a try statement which acts as an exception handler - a place where exception objects are dealt and caught with.

  • Q : Distinct features of Object oriented

    Q. What are the distinct features of Object oriented programming language?  

    Discover Q & A

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

    18,76,764

    1947026
    Asked

    3,689

    Active Tutors

    1455911

    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.