📜  C++中的basic_istream ::运算符>>

📅  最后修改于: 2021-05-30 05:49:54             🧑  作者: Mango

basic_istream ::运算符>>称为提取运算符。该运算符用于在输入字符串。

头文件:


句法:

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

参数:

  • a :这表示提取的字符存储在其中的值。

返回值: istream ::运算符>>返回basic_istream对象。

下面是说明std :: basic_istream :: operater >>的程序:

程序1:

// C++ code for basic_istream::operater>>
#include 
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;
}
输出:
a = 12
b = 12.2
c = false

程式2:

// C++ code for basic_istream::operater>>
#include 
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;
}
输出:
a = 144
b = 0.26
c = false

参考: http : //www.cplusplus.com/reference/istream/basic_istream/运算符%3E%3E /

要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”