Friday 24 April 2015

Unformatted I/O Operations

The stream classes of C++ support two member functions get( ) and put( ). The function get( ) is a member function of the input stream class istream and is used to read a single character from the input device.

The function put( ) is a member function of the output stream class ostream and is used to write a single character to the output device.

Get() function

It has the following syntax:

Void get(char);

Int get(void);


Both the function can fetch a white-space character including the blank space, tab and newline character. It is well known that, the member functions are invoked by their objects using dot operators.


Put() function

It has the following syntax:

Void get(char);
Int get(void);


It is a member function of the output stream class ostream prints a character
representation of the input parameter. The parameter can also be a numeric constant.

Getline () function

The getline() function reads a whole line of text that ends with new line or until
the maximum limit is reached.

Write() function

The write() function displays the characters in the string array or displays the
character up to the given size.

The syntax for the two functions are

Getline (variable, size);
Write(variable, size);

Sample Program

#include <iostream.h>
void main()
{
char *str1;
cout<<”Enter the string”;
cin.getline(str1,50);
int len = strlen(str1);
for(int I = 0;I<len;I++)
{
cout.write(str1,I);
cout<<endl;
}
}





No comments:

Post a Comment