Standard Input and Output Functions C++:
The “stdio” stands for standard input/output. This header file contains a large number of standard Input and Output functions that are used to get input from tile input devices and also to print results on output devices.
The commonly used functions of this header file and their description is given below.
The “getchar” Function:
This function is similar to “getch” & “getche” functions of “conio.h” header file, It is also used to get a single character from a standard input device, i.e. from tile keyboard during program execution. The main features of this function are:
• When a character is entered, it is displayed on the screen.
• Enter key must be pressed to complete the input.
Its syntax is:
[var = ] getchar ( );
The use of [var = ] is optional. It is used to store the value of the character entered from the keyboard.
The “putchar” Function:
The “putchar” stands for put character.
It is used to put or print a single character on the standard output device. i.e. the computer screen.
The “gets” Function:
This function is used to get (input) data into a string variable from the keyboard. Any type of characters including space & special characters can he entered using this function. Enter key is pressed after entering the string. When Enter key is pressed a null character is appended at the end of the string.
Its syntax is:
gets (strvar);
where
strvar represents the string type variable into which data is to be entered.
The data in a string type variable can also be entered by using “cin” object but this object is not the most suitable method of inputting data into string variables. When a space key is pressed during input process, the “cin” object immediately appends the null character (‘\O’) at that, place in the string. The characters entered after the spaces are not stored in the string variable.
The “put” Function:
It is used to print a string on the computer screen. The new line is inserted after printing the string.
Its syntax is:
puts (string);
The “string” may be a ring constant or string type variable.
• In case of a string constant, the string is enclosed in double quotes.
• In case of a string variable, it is written without using quotes.
comment closed