Home » Learn C++ » Get Function in C++

Get Function in C++

The “get” Function:

The “get” function is used to read a text file one character at a time. The pointer automatically shifts to the next character after reading a character. The syntax of this member function is:

object.get (var);

Where:

object: represents created object of ifstream (or fstream) class.
get: represents a member function of the object.
var: represents a char type variable used to store the character that is read from the file.

Program:

Write a program to read a text tile, one character at a time, and display the contents on the screen.
#include<iostream. h>
#include<fstream. h>
#include<conio .h>
#include<stdlib.h>
main( )

{
char ch;
itstream rrr (”data.txt”);
clrscr ( );
if ( !rrr )
{
cerr << “File opening error” <<endl;
exit(1)
}
while( rrr )

{

rrr.get (ch);

cout << ch;

}

}

Other Topics

comment closed

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Copyright © 2010 Information Village. All rights reserved.