basic_istream::get() in C++ with Examples
The basic_istream::get() is used to get the character. This function returns a one character if available, otherwise it will return end of the file.
Header File:
<iostream>
Syntax:
int_type get();
Parameters: The method basic_istream::get() doesn’t accept any parameter.
Return Value: The method basic_istream::get() returns a character if available, otherwise returns end of the file.
Below are the programs to illustrate basic_istream::get()
Program 1:
#include <bits/stdc++.h>
using namespace std;
int main()
{
istringstream gfg( "GeeksforGeeks" );
char a = gfg.get();
cout << "First character is: "
<< a << endl;
char b;
gfg.get(b);
cout << "After reading:" << a
<< " We got " << b << endl;
return 0;
}
|
Output:
First character is: G
After reading:G We got e
Program 2:
#include <bits/stdc++.h>
using namespace std;
int main()
{
istringstream gfg( "Computer" );
char a = gfg.get();
cout << "First character is: "
<< a << endl;
char b;
gfg.get(b);
cout << "After reading:" << a
<< " We got " << b << endl;
char c;
gfg.get(c);
cout << "Now we got : "
<< c << endl;
return 0;
}
|
Output:
First character is: C
After reading:C We got o
Now we got : m
Reference: std::basic_istream::get
Last Updated :
28 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...