Open In App

basic_istream::operator>> in C++

Last Updated : 22 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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::operator>>:
Program 1: 
 

CPP14




// C++ code for basic_istream::operator>>
#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: 
 

CPP14




// C++ code for basic_istream::operator>>
#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/
 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads