getline c, get c, put c and write c – Unformatted stream I/O functions
- getline c, get c, put c and write c – These functions are called unformatted stream IO functions where
- get() and put() can handle single character input and output and
- getline() and write() can handle multi character input and output.
- Header files for these above functions : “iostream.h”
Single character functions : get() and put()
Single Character functions are used for reading and displaying a single character respectively. These functions are :
- get() :
- The get() function is an input function.
- It fetches a single character and store it in a character variable.
- The get() is a member function of istream class and it is involved with an istream object cin.
char ch; cin.get(ch); // get a character from keyboard and assign it to ch.
- put() :
- The function put() is an output function and is used to output a character at a time.
- The put() function is also a member of ostream class and is involved with an ostream object cout.
Example of get() and put() :
char ch; while (cin.get(ch)!='\n') cout<<ch;
char ch; cin.get(ch); cout.put(ch); cout.put(65)
Multi Character Functions : getline() and write()
The single character functions defined above can handle single character at a time and cannot handle multiple characters. To solve this problem, there are functions that can handle strings also. These functions are :
- getline() –
- The getline() is an input function and needs a line of text that ends with a newline character.
- This function is used as shown below :
- where line specifies the name of the variable that will store the line of text, and
- size specifies that maximum size-1 characters can be stored in line;
- 1 extra character in size is reserved for null character ‘\0’.
- write() –
- The function write() is an output function and can display an entire line.
- It takes the following form :
- where line specifies the string variable whose contents are to be displayed, and
- size specifies the number of characters to be displayes.
Example of getline() and write() :
char name; cin.getline(name,30);
Incoming search terms:
- put and get function in c example
- put() example program
- getline() write() in c
- getline hindi notes
- Get in c
- get and put function in c example
- explain getline and write function
- difference between put() and write() in c
- write a program to display the character on the screen using get ()
- chracter io with get() and put () in c