basic_istream::get() in C++ with Examples Last Updated : 15 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: CPP14 // C++ code for basic_istream::get() #include <bits/stdc++.h> using namespace std; // Driver Code int main() { // Declare string stream istringstream gfg("GeeksforGeeks"); // Here we get H char a = gfg.get(); cout << "First character is: " << a << endl; char b; // Here we got e 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: CPP14 // C++ code for basic_istream::get() #include <bits/stdc++.h> using namespace std; // Driver Code int main() { // Declare string stream istringstream gfg("Computer"); // Here we get C char a = gfg.get(); cout << "First character is: " << a << endl; char b; // Here we got o gfg.get(b); cout << "After reading:" << a << " We got " << b << endl; char c; // Here we got m 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 Comment More infoAdvertise with us Next Article std::basic_istream::getline in C++ with Examples B bansal_rtk_ Follow Improve Article Tags : Misc C++ CPP-Functions Practice Tags : CPPMisc Similar Reads std::basic_istream::getline in C++ with Examples The std::basic_istream::getline is used to extract the characters from stream until end of line or the extracted character is the delimiting character. The delimiting character is the new line character i.e '\n'. This function will also stop extracting characters if the end-of-file is reached if inp 2 min read std::basic_istream::ignore in C++ with Examples The std::basic_istream::ignore is used to extracts characters from the input string and discards them including delimiting character, i.e., if the end of the file is reached this function stops extracting characters. The delimiting character is the new line character i.e '\n'. This function will als 2 min read basic_istream::swap() in C++ with Examples The basic_ios::swap(x) is used swap all data members of the base class except for rdbuf(), and swaps the values of the gcount() counters between *this and x. This basic_ios::swap(x) function is a protected function. Below is the syntax and the header file for the same: Header File: #include<iostr 2 min read basic_istream::peek() in C++ with Examples The std::basic_istream::peek() used to reads the next character from the input stream without extracting it. This function does not accept any parameter, simply returns the next character in the input string. Below is the syntax for the same: Header File: #include<iostream> Syntax: int peek(); 2 min read basic_istream::seekg() in C++ with Examples The basic_stream::seekg() method is used to set position of the next character to be extracted from the input stream. This function is present in the iostream header file. Below is the syntax for the same: Header File: #include<iostream> Syntax: basic_istream& seekg (pos_type pos); Paramet 2 min read basic_istream::unget() in C++ with Examples The basic_istream::unget() is used to unget the character and used to decrease the location by one character and makes the extracted character available for used once again. Header File: <iostream> Syntax: basic_istream& unget(); Parameters: The basic_istream::unget() method doesnât accept 2 min read Like