CPP Language / Iostream Library Classes

Class Name Details
ios class It is used to read and write input a sequence of characters.
istream Class It is used to read input as a sequence of characters by cin statement.
ostream class It is used to write a sequence of characters by cout statement.



Formatted I/O Function
Types of I/O Functions
No. Types of functions Details
1 Input functions It reads the input from the keyboard, file and network program<
2 Output functions It writes the output to console, file and network program

Types Of Input/output Functions
No. Functions Details
1 Formatted input/output functions. Used for performing input/output operations at console and the resulting data is formatted
2 Unformatted input/output functions. Used for performing input/output operations at console and the resulting data is unformatted

Unformatted Input/output Functions
No. Functions Description
1 get(char *) It is used to read a single character from user console.
2 get() It is used to read a single character from user console and returns it.
3 getline(char* arr, int size) It is used to Read a line of characters from user console.
4 put(char ch) It is used to write a single character at user console.
5 write(char *arr, int num) It is used to write a character array at user console.

Formatted Console Input/output Functions
Functions Method Description
width(int width) It is used to set the width of a value to be displayed in the output.
precision() It is used to set the number of the decimal point to a float value.
fill() It is used to set a character to fill in the blank space of a field
setf() It is used to set various flags for formatting output
unsetf() It is used to remove the flag setting

Formatted Console Input/output Functions Example
Program Output


#include
using namespace std;
void width()
{
cout << "Implementing width\n";
char c = 'W';
cout.width(4); // Adjusting width to 4.
cout << c <<"\n\n";
}
void precision()
{
cout << "Implementing precision\n"; cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
cout<<2.1234<<"\n\n";
}
void fill()
{
cout << "Implementing fill\n";
char c = 'W';
cout.fill('*');
cout.width(5);
cout< }

void setf()
{
cout << "Implementing setf\n";
int n=100;
cout.setf(ios::showpos);
cout< }

void unsetf()
{
cout << "Implementing unsetf\n";
cout.setf(ios::showpos|ios::showpoint);
cout.unsetf(ios::showpos);
cout<<400.0<<"\n\n";
}

int main()
{
width();
precision();
fill();
setf();
unsetf();
return 0;
}


Implementing width
W
Implementing precision
2.12
Implementing fill
****W
Implementing setf
+100
Implementing unsetf
400.00



Home     Back