Skip to content
Related Articles

Related Articles

basic_istream::operator>> in C++
  • Last Updated : 28 May, 2020

The basic_istream::operator>> is known as the extraction operator. This operator is used to apply on the input string.

Header File:

<iostream>

Syntax:

basic_istream& operator>>( int& a );
basic_istream& operator>>( unsigned int& a );

Parameters:

  • a : This represents the value where the extracted character are stored.

Return Value: The istream::operator>> returns the basic_istream object.



Below is the program to illustrate std::basic_istream::operater>>:

Program 1:




// C++ code for basic_istream::operater>>
#include <bits/stdc++.h>
using namespace std;
  
// Driver code
int main()
{
    // Declare the string "12 12.2 GeeksforGeeks"
    string gfg = "12 12.2 GeeksforGeeks";
  
    istringstream stream(gfg);
    int a;
    float b;
    bool c;
  
    stream >> a >> b >> boolalpha >> c;
    cout << "a = " << a << '\n'
         << "b = " << b << '\n'
         << "c = " << boolalpha << c << endl;
  
    return 0;
}
Output:
a = 12
b = 12.2
c = false

Program 2:




// C++ code for basic_istream::operater>>
#include <bits/stdc++.h>
using namespace std;
  
// Driver code
int main()
{
    // Declare the string "144 0.26 GFG"
    string gfg = "144 0.26 GFG";
  
    istringstream stream(gfg);
    int a;
    float b;
    bool c;
  
    stream >> a >> b >> boolalpha >> c;
    cout << "a = " << a << '\n'
         << "b = " << b << '\n'
         << "c = " << boolalpha << c << endl;
  
    return 0;
}
Output:
a = 144
b = 0.26
c = false

Reference: http://www.cplusplus.com/reference/istream/basic_istream/operator%3E%3E/

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :