Put and get functions

The function get () is a member function of the file stream class f stream, and is used to read a single character from the file. The function put () is a member function of the output stream class f stream, and is used to write a single character from the output file. The programme give below reads strings from the standard input device, and writes the same to a file character by character. A sequential file is developed and its pointer is placed at the start of the file. It is processed in sequence till the end of file is reached.

Programme in C++, writes and reads characters from the file

# include < f. Stream .h >     

Void main ()

{

Char C, string [75];

F stream file ("student. Txt", ios : : in / ios : : out);

Cout << "enter string :";

  Cin. Get line (string, 74);

For (Int I = 0, string [I]; I++)

File. Put (string [I]);   // writes a character

File. Seek g (0);            // seek to the beginning

Cout << "output string : ";

While (file)               // reads a character

{

File. Get (C);

 Cout << c;

}

}

   Related Questions in Programming Languages

  • Q : Explain the common uses of XML Explain

    Explain the common uses of XML.

  • Q : Explain While loop While loop: It is

    While loop: It is one of Java's three control structures employed for looping. The other two are: do loop and for loop. The while loop comprises of a Boolean expression and a loop body. The condition is tested prior to the loop body is entered for the

  • Q : What is Binary operator Binary operator

    Binary operator: It is an operator taking two operands. Java has numerous binary operators, like the arithmetic operators +, -, *, / and %, and the Boolean operators &&, || and ^, among others.

  • Q : Explain Polymorphism Polymorphism : It

    Polymorphism: It is the ability of an object reference to be employed as if it referred to an object with various forms. The polymorphism in Java outcomes from both class inheritance and interface inheritance. The actually different forms frequently o

  • Q : State De Morgans Theorem De Morgan's

    De Morgan's Theorem: The two rules which can help to simplify Boolean expressions comprising multiple logical-not operators in combination with the other Boolean operators.

  • Q : Explain the computer process Explain

    Explain the computer process.

  • Q : What is First in-first out First in,

    First in, first out: It is FIFO semantics of the queue data structure. Items are eliminated in the order in which they arrived in the queue; therefore older items are always eliminated before newer ones.

  • Q : Describe Software reuse Software reuse

    Software reuse: It is the ability to reuse software components in various contexts. The object-oriented languages aid to encourage reuse by their support of encapsulation.

  • Q : Define the term Arpanet Define the term

    Define the term Arpanet: It is a network which was a forerunner of the global Internet.

  • Q : What is an IP address IP address : An

    IP address: An Internet Protocol (abbreviated as IP) address for a networked computer. Presently, IP addresses comprises of 4-byte values, written in dotted decimal notation, like 129.12.0.1. In future, IP addresses will be 16-bytes long to accommodat

©TutorsGlobe All rights reserved 2022-2023.